Evolution Of Unix / Linux Shells

It’s really difficult to write about the evaluation or history of Unix / Linux shell. One can write pages after pages about these. I will try to cover the very basics of it and not diving deep into it. Let’s began than for an overview of most popular shells.

What is a Unix Shell?

A Unix shell is a command-line interpreter that’s interprets the command entered by the user. We enter a command and then it interprets that command and gives us the output of that command. A shell provides a traditional user interface for the Unix operating system and for Unix-like systems that we all are used to. Usually, black screen with a white text color. Users enter commands as plain text or we can create text scripts of one or more commands all together one after another.

The shell is your interface to the operating system. The way user can interact with the system. After you login to the Unix system, you are placed in a program which is called the shell.

Thompson Shell

According to history and many online materials, the very first Unix shell was the Thompson shell, sh, written by Ken Thompson at Bell Labs (The very famous Bell Labs). It was distributed with Versions 1 through 6 of Unix, from 1971 to 1975. It has features like piping, simple control structures using if and goto, and filename wildcarding. Now a days, it is not coming with modern Unix / Linux systems.

The PWB Shell

The PWB shell or Mashey shell, sh, was an updated version (it was a modified version) of the Thompson shell, written by John Mashey. It was written for encouraging shell programming. Some great features like if-then-else-endif, and switch and while constructs were introduced in this shell.

The Bourne Shell

The rise of Unix began with the Bourne shell. The Bourne shell, sh, was writen by Stephen Bourne at Bell Labs. And it gets distributed as the shell for UNIX Version 7 from 1979.

It has many basic features and later on those are inherited to many other Unix Shell like here documents, command substitution, more generic variables and built in control structures. Bourne shell program name is “sh” and its path in the Unix file system hierarchy is /bin/sh.

On many systems, Bourne Shell (sh) may be a symbolic link or hard link to one of these alternatives shell mentioned below

  • Almquist shell (ash)
  • Bourne-Again shell (bash)
  • Korn shell (ksh)
  • Z shell (zsh)

A Simple Bourne Shell Example

#!/bin/sh
echo "Hello World 1!"
echo "Hello World 2!"

Almquist shell (ash)

The Almquist shell is also known as A Shell, ash and sh. It’s a lightweight Unix shell originally written by Kenneth Almquist. It was written in the late 1980s. It’s a variant of the Bourne shell, and it replaced the original Bourne shell in the BSD versions of Unix released in the early 1990s. In some modern Linux distributions like Debian and Debian derived Linux distributions such as Ubuntu ship a version of ash, known as dash (Debian Almquist shell). Ash is also fairly popular in embedded Linux systems.

It is fast, small, and compatible with the POSIX standard’s specification of the Unix shell and may be that’s why it is being used on embedded devices. Ash did not supports command history mechanisms. However, few current variants of Ash Shell may support it.

Bourne-Again shell

Written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. Most popular and widely used among all of the shells. Every Linux distribution comes up with this shell. It provides a superset of Bourne Shell functionality. On most of the GNU/Linux distribution, this shell can be found installed and is the default interactive shell for users with /bin/bash path location. This is released in the year 1989.

Due to it’s popularity, it has been ported to Microsoft Windows and distributed with Cygwin and MinGW to serve the bash functionalities. For Android, via various terminal emulation applications.

It supports wildcard matching, piping, here documents, command substitution, variables and control structures for condition-testing (If – then – else if) and iteration (loop).

Bash scripts starts with the following syntax:

#!/bin/bash

Bash shell can also read commands from a file and can redirect the output to a file-using pipeline as well.

A Simple Bourne-Again Shell Example

#!/bin/sh
if [ $days -gt 365 ]
then
echo This is over a year.
fi

Korn shell (ksh)

Written by David Korn based on the Bourne shell sources. KornShell (ksh) is a Unix shell, which was developed & written by David Korn at Bell Labs in the early 1980s. As mentioned earlier, the initial development was based on Bourne shell source code. KornShell is backward-compatible with the Bourne shell.Also it includes many features of the C shell as well.

It has following variants

  • Dtksh
  • Tksh
  • Oksh
  • Mksh
  • Sksh
  • MKS Korn shell

A Simple Korn Shell (ksh) Example

#!/bin/ksh
print Disk space usage
du -k
exit 0

Z shell (zsh)

Paul Falstad wrote the first version of Zsh Shell in 1990. The Z shell (zsh) is a Unix shell that can be used as an interactive login shell and very powerful command interpreter for shell scripting as well. Actually, Zsh is an extended Bourne shell with a large number of improvements, which includes some features from bash, ksh, and tcsh.

The name Zsh derives from the name of Yale professor Zhong Shao as Paul Falstad was a student at Princeton University.

It has some good features like

  • Programmable command-line completion (Auto Completion).
  • Sharing of command history among all running shells.
  • Extended file globbing.
  • Improved variable or array handling.
  • Editing of multi-line commands in a single buffer.
  • Spelling correction and lot others.

C shell

The C shell is also known as Csh. While Bill Joy was a graduate student at University of California, he wrote C Shell. It is widely distributed with BSD Unix. It has some great features including the control structures and the expression grammar. The C shell also introduced a large number of new features for interactive work which includes history and editing mechanisms. Also aliases, cdpath, job control and path hashing, I/O redirection, joining, variable substitution, background execution etc.

Like all other Unix shells, it supports wildcard of filename, command piping, variables and control structures for condition-testing and iteration. csh is actually tcsh on many systems like as Mac OS X and Red Hat Linux. Tcsh is a improved version of Csh. But On Debian and some derivatives (including Ubuntu from Debian), there are two different packages: csh and tcsh.

A Simple C Shell Example

#!/bin/csh
if ( $days > 365 ) then
echo This is over a year.
endif

Here is a great link for knowing all the shell with comparison with each other.

That’s all for today. Hope you enjoyed it.