You are on page 1of 4

| Print | Contents |

Choosing a UNIX shell


Abstract
This article describes the distinguishing characteristics of each of the major UNIX shell environments, enabling you to choose which shell is most appropriate for a particular task.

The main shell families


There are several groups commonly called families of UNIX shell programs. The shell families were developed by different groups of developers for different purposes. The most important are the Bash shell, the Korn shell, and the TC shell.

The Bourne and Bash shells


The Bourne shell, created by Steve Bourne at AT&T, is the shell from which almost all modern UNIX shells are derived. It is still the most widespread shell program. It's installed as /bin/sh and it is found in every flavor of UNIX. This makes it particularly good for writing shell scripts, because scripts written for the Bourne shell will run on any UNIX system. You can add further scripting functionality to this shell by using the awk language interpreter and the sed stream editor within shell scripts. However, the Bourne shell is no longer widely used as an interactive shell. It has been largely replaced by the Bourne Again Shell. This shell is usually installed as /bin/bash and is better known as the Bash shell. The Bash shell was developed as part of the Gnu's Not UNIX (GNU) project. It has since become the default shell for Linux. The Bash shell is backwardly compatible with the Bourne shell for scripting purposes, and it contains additional interactive features derived from the Korn and C shells. For example, it provides a command-line history buffer. The up and down arrow keys allow you to scroll backwards and forwards through the command history. The Bash shell also allows you to edit a current command using the arrow keys and a mouse. These command-line editing features make it a user-friendly shell that is easy for beginners to learn.

The C and TC shells


The C shell, created at Berkeley by William Joy, uses syntax similar to that of the C programming language. This was meant to be useful for shell scripting, but it has never been widely used for that purpose. However, it was the first UNIX shell to feature a command history buffer, and so became popular as an interactive shell.

Unlike the Bash shell, the C shell does not allow users to scroll through the command history buffer. Instead, each previously executed command has an event number. Because of this cumbersome system and the fact that it isn't compatible with the Bourne shell, the C shell has mostly been displaced by other shells. The TC shell is an updated version of the C shell that allows command-line editing in two modes, one resembling the vi editor and the other resembling emacs. However, it has retained the drawbacks of the C shell, including incompatibility with the Bourne shell.

The Korn shell


Like the Bourne shell, the Korn shell was developed at AT&T. It uses the same syntax as the Bourne shell and is compatible with it, but it includes enhanced scripting features similar to those of the TC shell. For example, it allows command-line editing in vi and emacs mode. It's usually installed as /bin/ksh. The original version of the Korn shell is called ksh88 and was written by Dave Korn. There is also an updated version called ksh93, with improved scripting features. Independent software enthusiasts have created a clone of ksh93 called the Public Domain Korn shell (pdksh). This open-source version provides all the functionality of the Korn shell and also allows users to scroll through the command history buffer.

POSIX shells
The Portable Operating System Interface (POSIX) 1003.2 is a standard aimed at ensuring compatibility between UNIX shells. Both the Bash shell and the ksh93 version of the Korn shell satisfy the POSIX standard. There is also an updated version of the Bourne shell that meets the POSIX standard.

Shell features
The following table compares the interactive features and scripting features of the Bourne shell, the Bash shell, the Korn shell, and the TC shell. Features of the four main UNIX shells Bourne shell Korn shell Feature (sh) (ksh) Job control N Y Aliases N Y Shell functions Y Y Standard input/output redirection Y Y Directory stacks N Y Command histories N Y Command-line editing (vi/emacs) N Y

Bash shell (bash) Y Y Y Y Y Y Y Y Y N Y Y Y Y

TC shell (tcsh)

Features of the four main UNIX shells Bourne shell Korn shell Feature (sh) (ksh) Username lookup N Y Login and logout watching N N Filename, username, and hostname N Y completion History completion N N Fully programmable completion N N Co-processes N Y Built-in arithmetic evaluation N Y Transparent following of symbolic N Y links Periodic command execution N N Customizable prompts N Y Spelling correction N N Automatic mailbox checking N Y Noninteractive, non-login startup N Y files Bypass of user startup files N N Specifiable startup files N Y List variables N Y Full signal trap handling Y Y File noclobber ability N Y Local variables N Y

Bash shell (bash) Y N Y Y N N Y Y N Y N Y Y Y Y N Y Y Y Y Y Y Y Y N Y Y Y Y Y Y Y N N Y N Y N

TC shell (tcsh)

The Bourne shell has none of the advanced interactive and scripting features of the other shells. Its value lies in the fact that it's available in every flavor of UNIX and it is therefore useful for portability. The features of the Bash shell such as history completion make it especially useful for interactive use. By contrast, the Korn shell's features make it more suitable for writing and running shell scripts. For example, it supports list variables and co-processes, which the Bash shell does not. The TC shell shares many of the features of the Korn and Bash shells, and it supports additional features such as spelling correction and login watching. However, it lacks some of the scripting features of the other shells, such as shell functions and local variables.

Summary

The most popular shell environments are the Bourne shell, the Bash shell, the Korn shell, and the C shell. The Bourne shell is found on all UNIX systems, so it's a good shell for writing scripts that need to be compatible with diverse systems. The Bash shell is a version of the Bourne shell that includes additional features for interactive use. The C and TC shells use similar syntax to that of the C programming language. They're useful for scripting but are incompatible with the Bourne shell. The Korn shell is an extension of the Bourne shell that includes the enhanced scripting features of the C shell. The Portable Operating System Interface (POSIX) is a standard aimed at ensuring compatibility between UNIX shells. The Bash and Korn shells comply with the POSIX standard. There is also a version of the Bourne shell called the POSIX shell that has been updated to meet the POSIX standard.

Table of Contents
| Top of page | | Abstract | | The main shell families | | Shell features | | Summary | Copyright 2003 SkillSoft PLC. All rights reserved. SkillSoft and the SkillSoft logo are trademarks or registered trademarks of SkillSoft PLC in the United States and certain other countries. All other logos or trademarks are the property of their respective owners.

You might also like