A shell script is a list of commands in a computer program that is run by the Unix shell which is a command line interpreter. 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.
There are two major types of shells in Unix. These are:
This is the default shell for version 7 Unix. The character $ is the default prompt for the bourne shell. The different subcategories in this shell are Korn shell, Bourne Again shell, POSIX shell etc.
This is a Unix shell and a command processor that is run in a text window. The character % is the default prompt for the C shell. File commands can also be read easily by the C shell, which is known as a script.
The different capabilities of the shell script are −
Several commands that would be entered manually in a command line interface can be executed automatically using a shell script. This can be done without the user needing to trigger each command separately.
There are many features in modern shell scripts that are only found in sophisticated programming languages such as arrays, variables, comments etc. Many complicated applications can be written in shell scripts using these features. But there is a problem i.e. shell script languages don’t support classes, threading etc.
It is much more flexible to use loops, variables etc for multiple tasks in shell script. An example of this is a Unix shell script known as bash, which converts jpg images to png images.
There is a shortcut provided by a shell script for a system command where command options, environment settings or post processing apply. This still allows the shortcut script to act as a Unix command.
Some of the advantages of shell script are −
Some of the disadvantages of shell script are −
A script demo.sh is created for this example. The script and commands are given as follows −
#!/bin/bash gzip zip find echo
Here,
gzip is a command to create, extract or view .gz files,
zip is a command used to create or extract zip file,
find is a command that is helpful to search for a file,
echo is a command displays a line of text