Unix Shell Scripting by Chris Johnson

The shell referred to in these pages is always a Bourne-type shell; that is, a shell whose syntax is based on the Unix shell introduced by Steven Bourne in 1978 (or thereabouts), with some later improvements. On all Unix systems, a Bourne-type shell can be found in /bin/sh. On most modern systems, this will be somewhat better than the Bourne shell — it will be a POSIX shell. If it is not, there should be a POSIX-compliant shell elsewhere on the system.

A POSIX shell is a Bourne shell with a number of extensions (which are mostly derived from the Korn Shell). The most important ones perform string manipulation and integer arithmetic. In a Bourne shell, arithmetic operations require an external program (e.g., expr, awk or bc) as does finding the length of a string, or cutting a string into pieces. POSIX has $((...)) for integer arithmetic and parameter expansions for string operations.

Generally, scripts and snippets published here are designed to run in a POSIX shell. Some will run in a Bourne shell, and those that will not should not be hard to convert (in the unlikely event that you find it necessary). A few scripts require added extensions found in bash and ksh.

What, no csh?

Before POSIX shells became generally available, many people used the C shell as their interactive shell. It has a number of features that were lacking in the Bourne shell, including arithmetic and command history. However, when it comes to writing scripts, it has many drawbacks that are discussed in these three articles:

  1. Top Ten Reasons not to use the C shell
  2. C shell problems
  3. Csh Programming Considered Harmful

Since, as Bruce Barnett says in the first of the above articles, "UNIX was hard enough to learn, and spending months to learn two shells seemed silly", I recommend using a Bourne-type interactive shell, and I specifically recommend bash.

If you need help with a csh problem, try Bruce Barnett's csh page.