Tuesday, July 22, 2014

A quick glance at the shell script

A quick glance at the shell script

Linux system consists of several components, the most important of these components is the Linux kernel which is the heart of the system, the so-called Shell that takes Linux kernel as casing.

Bash is in all Linux distributions almost, it is responsible for the implementation of the terminals commands as an example, and it is responsible for taking commands and passed them to the kernel and deal with them, which is very useful and depend on them most of the Linux applications.

When you execute ls command, for example, which lists all the files and folders in the current path in the terminal, the Bash automatically execute the program in /bin/ls, then the program is executed and the components are listed the current path.

Shell script is a set of serial commands that are written for a particular job, you can perform anything and modify anything you want the system via the shell script, the Bash reads the commands and instructions from a shell script and it is implemented to perform the task that it was designed for.

Shell script does not require simple commands such as ls and pwd, it can contain conditional sentences  like if and functions and variables and things very complicated, it differs from the use of these things, each according to the goal of shell scripts.

This is an example of a very simple shell script file which will ask for your name and your age, then print them in the screen, take these commands and save them in a file in a folder, for example test.sh  in the home directory :

#! / bin / bash 
echo "Enter your name:"; read name 
echo "Enter your age:"; read age 
echo "Hello $ name, you are $ age years old!" 

Then run the following command to make it executable :

chmod +x test.sh 

Now to execute shell scripts, do as this :

. / test.sh 

Enter your name, and enter your age, and will print the sentence .. Of course this is a very simple example to give you an idea about it, writing useful shell scripts needs a higher level than that, you can learn shell scripts from some online Guides.


Share this article :


Post a Comment