As noted earlier, Unix shells are all fully-featured programming languages as well as simple ways of invoking programs. A file containing a number of shell commands is called a shell script.
Simple shell scripts are simply a sequence of simple commands (such as are many .profile files). However, a full set of iterative and conditional constructs are also available. The manual pages for each shell will give a complete description of the features available; though they do tend to be fairly cryptic and often a book from the book shop is a more useful approach to learning shell scripting.
The very big advantage of shell scripts is that they provide a simple way of automating a number of otherwise manual tasks. If you need to type a sequence of commands in more than twice, you probably want to write shell script. Remember, we programmers are all tool makers; we like making things easier for ourselves.
For a shell script to be usable as a program:
).
).Finally, it is traditional, though not at all compulsory, for shell scripts to be written in Bourne (or compatible) shell; this makes portability easier.
But keep an open mind. For a number of problems, other tools such as perl, tcl/tk or awk might be a better solution. It is worth being familiar with a number of tools so that you can use the right tool for each task.
Loc Van Huynh 2007-03-15