[Next] [Previous] [Up] [Top] [Contents]

CHAPTER 9 Shell Programming

9.1 Shell Scripts


You can write shell programs by creating scripts containing a series of shell commands. The first line of the script should start with #! which indicates to the kernel that the script is directly executable. You immediately follow this with the name of the shell, or program (spaces are allowed), to execute, using the full path name. Generally you can count on having up to 32 characters, possibly more on some systems, and can include one option. So to set up a Bourne shell script the first line would be:

#! /bin/sh

or for the C shell:

#! /bin/csh -f

where the "-f" option indicates that it should not read your .cshrc. Any blanks following the magic symbols, #!, are optional.

You also need to specify that the script is executable by setting the proper bits on the file with chmod, e.g.:

% chmod +x shell_script

Within the scripts # indicates a comment from that point until the end of the line, with #! being a special case if found as the first characters of the file.


Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]