when used interactively (e.g. command line history recall) and other commands are too complex to use interactively.
The shell itself has limited capabilities -- the power comes from using it asa "glue" language to combine the standard Unix utilities, and customsoftware, to produce a tool more useful than the component parts alone.
Any shell can be used for writing a shell script. To allow for this, the firstline of every script is:
characters tell the system to locate the following pathname, start itup and feed it the rest of the file as input.
program which can readcommands from a file can be started up this way, as long as it recognizesthe
comment convention. The program is started, and then the script fileis given to it as an argument. Because of this, the script must be readableas well as executable. Examples are perl, awk, tcl and python.
Any file can be used as input to a shell by using the syntax:
If the file is made executable using
, it becomes a new commandand available for use (subject to the usual $PATH search).
chmod +x myscript
A shell script can be as simple as a sequence of commands that you typeregularly. By putting them into a script, you reduce them to a single command.
2:date3: pwd4:du -k(2)
Why use Shell Scripts
Combine lengthy and repetitive sequences of commands into a single,simple command.
Generalize a sequence of operations on one set of data, into a procedurethat can be applied to any similar set of data.(e.g. apply the same analysis to every data file on a CD, without needingto repeat the commands)
Create new commands using combinations of utilities in ways the originalauthors never thought of.
Simple shell scripts might be written as shell aliases, but the script can bemade available to all users and all processes. Shell aliases apply only tothe current shell.