Previous Table of Contents Next

Bourne Shell

The Bourne shell, written by Steve Bourne when he was at AT&T Bell Laboratories, is the original UNIX shell. This shell is preferred for shell programming because of its programming capabilities and its universal availability. It lacks features for interactive use, such as built-in arithmetic and the capability to recall previous commands (history). The Bourne shell is the default login shell for the root account, and it serves as the default user login shell if you do not specify another shell in the user's passwd file. The Bourne shell is used for all system-supplied administration scripts.

The Bourne shell command is /bin/sh. The default prompt for the Bourne shell is a dollar sign ($). The root prompt is a pound sign (#).

Korn Shell

The Korn shell, written by David Korn of AT&T Bell Laboratories, was designed to be compatible with the Bourne shell and to offer interactive features comparable to the C shell. The Korn shell includes convenient programming features such as built-in integer arithmetic, arrays, and string-manipulation facilities. The Korn shell runs faster than the C shell, and runs virtually all scripts that are written for the Bourne shell.

The Korn shell command is /bin/ksh. The default prompt for the Korn shell is a dollar sign ($). The root prompt is a pound sign (#).

C Shell

The C shell, written by Bill Joy when he was at the University of California at Berkeley, was designed to incorporate features such as aliases and command history for interactive use. The syntax for its programming features is similar to that for the C programming language.

The C shell command is /bin/csh. The default prompt for the C shell is the system name followed by a percent sign (%). The root prompt is the system name followed by a pound sign (#).

Understanding How Shells Process Commands

Each shell creates subshells and child processes—subordinate shells and processes that are executed within the originating, or parent, shell—to interpret and execute commands. For example, the following list shows a simplified version of the order in which the Korn shell processes commands:

1.  Parses (divides up) the command into units separated by the fixed set of metacharacters: Space Tab Newline ; ( ) < > | &. Types of units include words, keywords, I/O redirectors, semicolons, and others.
2.  Checks the first part of each unit for shell keywords, such as function or if statements, with no quotes or backslashes. When it finds a keyword, the shell processes the compound command.
3.  Searches the list of aliases.
4.  Expands any tilde (~) expressions.
5.  Substitutes variables.
6.  Substitutes commands.
7.  Substitutes arithmetic expressions.
8.  Splits the items that result from parameter, command, and arithmetic substitution and splits them into words again.
9.  Expands wildcards.
10.  Looks up built-in commands, functions, and executable files.
11.  Sets up I/O redirection.
12.  Runs the command.

The Bourne shell interprets commands similarly, but does not check for aliases, tildes, or arithmetic. The C shell interprets commands in a different order.

Naming Shell Scripts

When you assign a name to a shell script, follow the general rule for naming Solaris 2.x files. Make a script name as descriptive as possible so that you can easily remember its designated function. Be careful to avoid names that Solaris 2.x itself uses for its own programs unless you intend to replace those utilities with your own scripts.

Each shell has a list of built-in commands. You should also avoid using built-in shell commands as script names. If you name a file with one of the shell built-in commands—such as alias, break, case, cd, continue, echo, else, exit, or history for the C shell—the shell interprets the script name as a built-in shell command and tries to execute it instead of executing the script. For example, with the Bourne or Korn shell, you will run into trouble if you name a script "test," which you might easily do if you are testing something out, because test is a built-in Bourne and Korn shell command. Refer to the shell syntax sections in Chapter 17 and to the sh(1), ksh(1), and csh(1) manual pages for a complete list of built-in commands.

Previous Table of Contents Next