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 procedure that can be
applied to any similar set of data.
(e.g.
apply the same analysis to every data file on a CD, without needing to repeat the commands)
- Create new commands using combinations of utilities in ways the original authors
never thought of.
- Simple shell scripts might be written as shell aliases, but the script can be made available to all users
and all processes. Shell aliases apply only to the current shell.
- Wrap programs over which you have no control inside an environment that you can control.
e.g. set environment variables, switch to a special directory, create or select a configuration file,
redirect output, log usage, and then run the program.
- Create customized datasets on the fly, and call applications (e.g. matlab, sas, idl, gnuplot) to work
on them, or create customized application commands/procedures.
- Rapid prototyping (but avoid letting prototypes become production)
Typical uses
- System boot scripts (/etc/init.d)
- System administrators, for automating many aspects of computer maintenance, user account
creation etc.
- Application package installation tools
Other tools may create fancier installers (e.g. tcl/tk), but can not be assumed to be installed already. Shell scripts are used because they are very portable. Some software comes with a complete installation of the tool it wants to use
(tcl/tk/python) in order to be self contained, but this leads to software bloat.
- Application startup scripts, especially
unattended applications (e.g. started from
cron or at)
- Any user needing to automate the process of setting up and running commercial applications,
or their own code.
AUTOMATE, AUTOMATE, AUTOMATE