top of page

Choosing a UNIX shell

Updated: Oct 20, 2023

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. 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 Feature Bourne shell (sh) Korn shell (ksh) Bash shell (bash) TC shell (tcsh) Job controlNYYYAliasesNYYYShell functionsYYYNStandard input/output redirectionYYYYDirectory stacksNYYYCommand historiesNYYYCommand-line editing (vi/emacs)NYYYUsername lookupNYYYLogin and logout watchingNNNYFilename, username, and hostname completionNYYYHistory completionNNYYFully programmable completionNNNYCo-processesNYNNBuilt-in arithmetic evaluationNYYYTransparent following of symbolic linksNYYYPeriodic command executionNNNYCustomizable promptsNYYYSpelling correctionNNNYAutomatic mailbox checkingNYYYNoninteractive, non-login startup filesNYYYBypass of user startup filesNNYNSpecifiable startup filesNYYNList variablesNYNYFull signal trap handlingYYYNFile noclobber abilityNYYYLocal variablesNYYN

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.


*EOD

11 views0 comments

Recent Posts

See All

Understanding UNIX shell scripts

Understanding UNIX shell scripts Audience: This tutorial assumes you have little knowledge about UNIX/Linux Operating System and its...

Comments


IT solutions to achieve operational excellence

bottom of page