UNIX / Linux : What Is a Shell? What are different Shells?

What Is a Shell?

A shell is a program that provides an interface between a user and an operating system (OS) kernel. An OS starts a shell for each user when the user logs in or opens a terminal or console window.

A kernel is a program that:

  • Controls all computer operations.
  • Coordinates all executing utilities
  • Ensures that executing utilities do not interfere with each other or consume all system resources.
  • Schedules and manages all system processes.

By interfacing with a kernel, a shell provides a way for a user to execute utilities and programs.

User Environment

The shell also provides a user environment that you can customize using initialization files. These files contain settings for user environment characteristics, such as:

  • Search paths for finding commands.
  • Default permissions on new files.
  • Values for variables that other programs use.
  • Values that you can customize.

What are the different Shells?

The following sections describe OS shells mostly available on UNIX/Linux Operating system. Shell features and their default prompts are also described.

1. The Bourne Shell

The Bourne shell (sh), written by Steve Bourne at AT&T Bell Labs, is the original UNIX shell. It is the preferred shell for shell programming because of its compactness and speed. A Bourne shell drawback is that it lacks features for interactive use, such as the ability to recall previous commands (history). The Bourne shell also lacks built-in arithmetic and logical expression handling.

The Bourne shell is the Solaris OS default shell. It is the standard shell for Solaris system administration scripts. For the Bourne shell the:

  • Command full-path name is /bin/sh and /sbin/sh.
  • Non-root user default prompt is $.
  • Root user default prompt is #.

2. The C Shell

The C shell (csh):

  • Is a UNIX enhancement written by Bill Joy at the University of California at Berkeley.
  • Incorporated features for interactive use, such as aliases and command history.
  • Includes convenient programming features, such as built-in arithmetic and a C-like expression syntax.

For the C shell the:

  • Command full-path name is /bin/csh.
  • Non-root user default prompt is hostname %.
  • Root user default prompt is hostname #.

3. The Korn Shell

The Korn shell (ksh):

  • Was written by David Korn at AT&T Bell Labs
  • Is a superset of the Bourne shell.
  • Supports everything in the Bourne shell.
  • Has interactive features comparable to those in the C shell.
  • Includes convenient programming features like built-in arithmetic and C-like arrays, functions, and string-manipulation facilities.
  • Is faster than the C shell.
  • Runs scripts written for the Bourne shell.

For the Korn shell the:

  • Command full-path name is /bin/ksh.
  • Non-root user default prompt is $.
  • Root user default prompt is #.

4. The GNU Bourne-Again Shell

The GNU Bourne-Again shell (bash):

  • Is compatible to the Bourne shell.
  • Incorporates useful features from the Korn and C shells.
  • Has arrow keys that are automatically mapped for command recall and editing.

For the GNU Bourne-Again shell the:

  • Command full-path name is /bin/bash.
  • Default prompt for a non-root user is bash-x.xx$. (Where x.xx indicates the shell version number. For example, bash-3.50$)
  • Root user default prompt is bash-x.xx#. (Where x.xx indicates the shell version number. For example, bash-3.50$#)

Here is a short comparison of the all 4 shells and their properties.

Shell Path Default Prompt (non-root user) Default Prompt (Root user)
The Bourne Shell (sh) /bin/sh and /sbin/sh $ #
The C Shell (csh) /bin/csh % #
The Korn Shell (ksh) /bin/ksh $ #
The GNU Bourne-Again Shell (Bash) /bin/bash bash-x.xx$ bash-x.xx#
Related Post