Last revision August 6, 2004
This discussion applies to scripts written for the C-shell (csh). Bourne shell (sh) scripts are similar, although the exact syntax differs.
A shell script is a file containing a set of commands to be executed (run) by the shell in sequence as it reads the file.
In its simplest form, a shell script is simply a way to save a set of commands that are often executed, such as the initialization commands for your login session that are stored in the .login script file, so you don't have to re-type the set everytime you want to run it. Instead, you simply run the script that contains all the commands.
Strictly speaking, everything that you can put into a shell script can also be executed interactively by typing on the command line, although the looping constructs can be cumbersome. This gives you the chance to test out the syntax of various shell constructs.
The shell provides tools to make shell scripts more powerful, even full-fledged programs. Shell programming is organized around the concepts of "substitution" and "flow-of-control".
- Substitution is used to manipulate values within the script. It involves using the values of variables as part of a command; and taking the output of a command to be the new value of a variable.
- Flow-of-control refers to common programming constructs such as loops and if-then-else statements that are used to control which statements in the script are executed in which order, often depending upon the value of a variable; or to cause repetitive execution of a set of commands with different variable or input values.