Pages

Sunday, February 7, 2016

Bash Scripting

 What is a Shell Script...?                     


   In Unix the users  can enter commands either directly or through a file with set of written commands in it. It is called a shell program or a shell script. These shell scripts are interpreted, and not compiled. That is the shell reads commands line by line from the script and searches those command in the system.In other words, shell script is a computer program designed to be run by Unix Shell.

Above describes a basic function of a shell : passing commands to the kernal.
        

 Shell Types

 

 Why Bash......?   


                     Bash is the GNU shell and it is a sh compatible shell. It incoorporate useful features from other shells thus shows a functional improvements than others

  • interactive shell
  • allows integer arithmetic
  • shell maintains a list of aliases and they allow a string to be substituted for a word
  • provides one dimensional arrays of unlimited size
  • unlimited size command history
  • provide job control commands like jobs ,fg,bg,wait,kill,suspend,killall etc.

 Executing a program from a script


                 When there is a shell script to be executed, bash will create an exact copy of it and creates a new process. This child process created has the same environment as its parent, but  only its process ID number is different. This process is referred as Forking.

                 Now the child process created runs and the parent awaits till it finishes. During the process, the sub shell reads one line from the shell script at a time and then interprets and executes it. Once every line in the shell script is read, the sub shell terminates and the parent shell awakens to give a new prompt


 

No comments:

Post a Comment