This shell script and shell programming site aims to provide book reviews and free ebook on bash shell, korn shell, shell commands, linux shell, awk shell, unix commands, ftp shell and all other shells.

Programming the UNIX/linux Shell

Claude Cantin (claude.cantin@nrc.ca)
http://www.nrc.ca/imsb/rcsg
This document was produced by Claude Cantin of the National Research Council of Canada. Reproductions are permitted for non-profit purposes provided the origin of the document is acknowledged.

Programming the Shell

This chapter will concentrate on programming the shells. All examples shown will use the Bourne shell. Most shell scripts are written in the Bourne shell because it is the only shell found on *ALL* UNIX systems. Scripts written in the Korn shell are gaining popularity.

C shell scripts are possible, but not recommended. Although the C shell is great for interactive work, it has many drawbacks in script programming.

Bourne - C shell comparisons
A Bourne Shell Script is a file containing a series of Bourne Shell commands, as well as control structures such as if statements, while loops, etc. Parameters can be passed to the script and data can be read from the keyboard.
Bourne shell scripts are usually Algol-66 look-alikes, whereas C shell scripts look more like C program constructs.
The C shell is slower to start execution (as it looks in the .cshrc file EVERY TIME it is called) and produces a hash table of all paths for faster execution. The Bourne shell is slower, but starts executing immediately.
For that reason, short scripts are executed much faster in the Bourne Shell than the C shell (this is noticeable for small SLOW machines; with systems running at 30 to 130 MIPS/CPU, the difference in speed is almost insignificant). Large scripts should most likely be written in a compiled language--preferably C--because compiled code executes much faster than interpreted code.
Many features of the Bourne shell are also found in the C shell. Parameters are interpreted in the same way. Variable assignments are very similar. UNIX commands are exactly the same. Control structures and comparisons differ the most.

Followers