Archive for the ‘Unix shells’ Category

Thompson Shell

Saturday, May 8th, 2010

The Thompson shell was the first Unix shell, introduced in the first version of Unix in 1971, and was written by Ken Thompson. It was a simple command interpreter, not designed for scripting, but nonetheless introduced several innovative features to the command line interface and led to the development of the later Unix shells.

The name “shell” for a command line interpreter and the concept of making the shell a user program outside of the operating system kernel were introduced in Unix’s precursor Multics.

An early feature of the Thompson shell was a compact syntax for input/output redirection. In Multics, redirecting the input or output of a command required separate commands to start and stop redirection; in Unix, one could simply add an argument consisting of the < symbol followed by a filename for input or the > symbol for output to the command line, and the shell would redirect I/O for the duration of the command. This syntax was already present by the release of the first version of Unix in 1971.

A later addition was the concept of pipes. At the suggestion of Douglas McIlroy, the redirection syntax was expanded so that the output of one command could be passed to the input of another command. The original pipe syntax, as described in the Version 3 manual, was

command1 >command2>
This syntax proved too ambiguous and was easily confused with redirection to and from files. By Version 4, the syntax had changed to use the | symbol for pipes:

command1 | command2
The Thompson shell syntax for redirection and piping has proven durable, having been adopted by most other Unix shells and several other operating systems, most notably MS-DOS.

Decline and replacements
The shell’s design was intentionally minimalistic; even the if and goto statements, essential for control of program flow, were implemented as separate commands. As a result, by the 1975 release of Unix Version 6, it was becoming clear that the Thompson shell was inadequate for most serious programming tasks.

At this time, the developers of the Programmer’s Workbench UNIX distribution, most notably John Mashey, began modifying the Thompson shell to make it more suitable for programming. The result, known as the PWB shell or the Mashey shell, included more advanced flow-control mechanisms and introduced shell variables, but remained limited by the necessity to remain compatible with the Thompson shell.

Finally, the Thompson shell was replaced as the main Unix shell by the Bourne shell in Unix Version 7 and the C shell in 2BSD, both released in 1979. Since virtually all modern Unix and Unix-like systems are descended from V7 and 2BSD, the Thompson shell is generally no longer used. It is, however, available as open source as part of several Ancient Unix source distributions, and has been ported to modern Unices as a historical exhibit.


Saturday, May 8th, 2010

tcsh (pronounced “T-shell”) is a Unix shell based on and compatible with the C shell (csh). It is essentially the C shell with (programmable) filename completion, command-line editing, and a few other features.

The ‘t’ in tcsh comes from the T in TENEX, an operating system which inspired Ken Greer, the author of tcsh, with its command-completion feature. Ken Greer worked on tcsh in the late 1970s at Carnegie Mellon University. Paul Placeway from Ohio State University continued work on it in the 1980s, and since then it has been maintained by numerous people. Wilfredo Sanchez, the former lead engineer of Mac OS X, worked on tcsh in the early 1990s at MIT.

Early versions of Mac OS X shipped with tcsh as the default shell, but it has since been replaced by bash.

PWB Shell

Saturday, May 8th, 2010

The PWB shell (also known as the Mashey shell) was an early Unix shell distributed with some versions of Programmer’s Workbench UNIX circa 1975-1977. It was a modified (and generally constrained to be upward-compatible) version of the Thompson shell with additional features to increase usability for programming, and was maintained by John Mashey and various others (Dick Haight, Alan Glasser).

Although it was soon superseded by the Bourne shell, several features introduced in the PWB shell remain in many later shells. The if and goto commands were made internal to the shell, and extended to allow if-then-else-endif, and switch and while constructs were introduced, as well as onintr to ignore interrupts or catch them to perform cleanup. Simple variables could be used, although their names were limited to one letter and some letters were reserved for special purposes, of which some are the precursors of the Environment variables found in all UNIX Systems from Edition VII onward.

For example, The $s variable was the ancestor of $HOME, used to avoid hard-coding pathnames. The $p variable was the ancestor of $PATH, which let users search for commands in their own choice of directories. Unlike most of the UNIX systems of the time, the original PWB/UNIX computer center was shared by multiple programming groups who could not change the contents of /bin or /usr/bin, but wanted to create their own sets of shared commands. In addition, the shell’s command-searching was enhanced to allow shell procedures to be invoked like binary commands, i.e., if the shell found a non-binary file marked executable, it would fork another shell instance to read that file as a shell script. Thus people could type command arguments rather than sh pathname/command arguments. All this behavior was packaged as the function pexec, which was the ancestor of execvp. to allow any program to invoke commands in the same way as the shell.

The $ character, used previously for identifying arguments to a shell script, became the marker for dereferencing a variable, and could be used to insert a variable’s value into a string in double quotes. (In addition to later shells, this feature would also later appear in the Perl and PHP programming languages.)

These features could not overcome the shortcomings of the Thompson shell, and so a new shell was written from scratch by Stephen Bourne. This Bourne shell was incompatible with the Thompson and PWB shells, but included equivalents of most of the PWB shell’s features, but done from scratch, rather than incrementally, with much discussion among the various participants. In particular, Environment variables and related machinery were designed by Stephen Bourne, John Mashey, and Dennis Ritchie as a general mechanism to replace the earlier, more limited features. After the adoption of the Bourne shell as the standard shell in Version 7 Unix, use of the PWB shell was phased out, although for a while, there was an internal Bell Labs course called Bourne Shell Programming for Mashey Shell Programmers. (The C shell, developed before the public release of the Bourne shell, also inherited some of the features of the PWB shell.)