A script is simply a file that contains shell commands; it can range in complexity from one line to a big program. Before we can execute a script, we must make the script file executable by using the chmod command as follows:

% chmod +x filename

where filename is the name of the script (the chmod command is discussed in the section on file permissions).

We can then run the script by typing its filename at the xterm prompt. If csh fails to find the executable, then we must specify the script's name in the form ./executable, where [.] designates the current directory and executable is the name of the script.

When a script is run, Unix determines which shell the script is written for, and then starts the appropriate shell to execute the commands in the script. Unix makes this decision by examining the first line of the script:

To prevent confusion, it is a good habit to always specify the name of the shell in the form #!pathName. Also, just like when we program in any other language, it is important to include comments in the script to ensure legibility. When the pound sign appears on any other line apart from the first line, all characters from the pound sign to the end of that line are treated as a comment.