What is Shell Script?
Bunch of commands in a computer program which is run by the Unix Shell by the
command line interpreter is called as Shell script.
A shell script usually has comments that
describe the steps. The different operations performed by shell scripts are
program execution, file manipulation and text printing.
A wrapper is also a kind of shell script
that creates the program environment, runs the program etc.
Shell scripts are reduces the efforts required by the end use.
Follow below steps to create a shell
script:
- Create a file using a vi editor (or any other editor). Name script file with extension .sh
- Start the script with #! /bin/sh
- Write some code.
- Save the script file as filename.sh
- For executing the script type bash filename.sh
Why Shell Scripts?
As being set of Linux commands, a shell script can be used to
achieve one or more tasks. For example, a script could be written to start a
database, shutdown a database, start backup, check whether a specific service
is up, and if not it could start it. So many other tasks can be done using
shell scripts. In general, when a specific task is frequently needed, it is
wise to write a script that can do it for you. This is much better than having
to remember, and type the commands every time the task is needed (which is both
silly and error-prone job). Writing shell scripts half-automates the
administration tasks, saves the administrator’s time, and minimizes typos
effects.
Advantages of Shell Script
Below are the few advantages of shell scripting:
- The commands and syntax of the shell script are the same as that entered at the command line. Because of this, there is no need to switch to a completely different syntax.
- It is much faster to write a code in shell script than in other programming languages. This also means that the program is easier to create and files required can be selected easily.
- Shell script can also be used to provide linkage for already existing programs.
- Shell scripting can be used by users that are not experts to modify and tailor the behavior of their programs according to their requirements.
- Quickly Start
- Interactive debugging
Disadvantages of Shell Script
Below are the few disadvantages of shell scripting:
- There may be errors in shell scripting that prove to be quite costly.
- The programs in shell script are quite slow while executing and a new process is required for every shell command executed.
- Different platforms in shell scripting may also have compatibility problems.
Types of Shell
- The Bourne Shell
- The C Shell