Shell script is series of commands to be run by the shell. Shell script performs file manipulation, program execution, and printing text, sets up the environment, and does any necessary cleanup, logging, etc.
Shell scripts allow several commands that would be entered manually at a command-line interface to be executed automatically, and without having to wait for a user to trigger each stage of the sequence.
Visit Wikipedia for detailed information, advantages and disadvantages.
First Shell Script
It is convension to give files that are Bash scripts an extension of .sh
#!/bin/bash # First Script echo Hello World !
Line 1: #! is called a SHEBANG charecter, it tells the script to interpret the rest of the lines with an Interpreter /bin/bash/. So if we change that to /usr/bin/python then it tells the script to use python interpreter.
Line 2: Anything after # is not executed (comments). It is for our reference only.
Line 3: echo command will print a message on the screen. If you type this command yourself on command line, it will behave exactly same.
Executing a script
Executing a script is fairly easy. Before execute a script, it must have execute permission. Otherwise you will get “Permission denied” error message.
Without giving execute permission also we can run the script but we have to provide as shell and ask it to run all the commands on that shell.