: the original Bourne shell
manual page.
PDP-11 simulation with
SIMH Origins Work on the Bourne shell initially started in 1976. Developed by
Stephen Bourne at
Bell Labs, it was a replacement for the
Thompson shell, whose executable file had the same name—sh. The Bourne shell was also preceded by the
Mashey shell. Bourne was released in 1979 in the
Version 7 Unix release distributed to colleges and universities. Although it is used as an interactive command interpreter, it was also intended as a
scripting language and contains most of the features that are commonly considered to produce structured programs. It gained popularity with the publication of
The Unix Programming Environment by
Brian Kernighan and
Rob Pike—the first commercially published book that presented the shell as a programming language in a tutorial form. Some of the primary goals of the shell were: • To allow
shell scripts to be used as
filters. • To provide programmability including
control flow and
variables. • Control over all input/output
file descriptors. • Control over
signal handling within scripts. • No limits on string lengths when interpreting shell scripts. • Rationalize and generalize string quoting mechanism. • The
environment mechanism. This allowed context to be established at startup and provided a way for shell scripts to pass context to sub scripts (
processes) without having to use explicit
positional parameters.
Features of the original version Features of the Version 7 UNIX Bourne shell include: • Scripts can be invoked as commands by using their filename • May be used interactively or non-interactively • Allows both synchronous and asynchronous execution of commands • Supports input and output redirection and pipelines • Provides a set of built-in commands • Provides flow control constructs and quotation facilities. • Typeless variables • Provides local and global variable scope • Scripts do not require compilation before execution • Does not have a goto facility, so code restructuring may be necessary •
Command substitution using
backquotes: `command`. •
Here documents using << to embed a block of input text within a script. • for ~ do ~ done loops, in particular the use of $* to loop over arguments, as well as for ~ in ~ do ~ done loops for iterating over lists. • case ~ in ~ esac selection mechanism, primarily intended to assist
argument parsing. • sh provided support for environment variables using keyword parameters and exportable variables. • Contains strong provisions for controlling input and output and in its
expression matching facilities. The Bourne shell also was the first to feature the convention of using
file descriptor 2> for
error messages, allowing much greater programmatic control during scripting by keeping error messages separate from data. Stephen Bourne's coding style was influenced by his experience with the
ALGOL 68C compiler that he had been working on at
Cambridge University. In addition to the style in which the program was written, Bourne reused portions of
ALGOL 68's
if ~
then ~
elif ~
then ~
else ~
fi,
case ~
in ~
esac and
for/
while ~
do ~
od" (using done instead of
od) clauses in the common
Unix Bourne shell syntax. Moreover, – although the v7 shell is written in
C – Bourne took advantage of some
macros to give the C
source code an ALGOL 68 flavor. These macros (along with the
finger command distributed in Unix version
4.2BSD) inspired the
International Obfuscated C Code Contest (IOCCC).
Features introduced after 1979 Over the years, the Bourne shell was enhanced at AT&T. The various variants are thus called like the respective AT&T Unix version it was released with (some important variants being Version7, System III, SVR2, SVR3, SVR4). As the shell was never versioned, the only way to identify it was testing its features. Features of the Bourne shell versions since 1979 include: • Built-in command – System III shell (1981) • # as comment character – System III shell (1981) • Colon in parameter substitutions "${parameter:=word}" – System III shell (1981) • with argument – System III shell (1981) • for indented here documents – System III shell (1981) • Functions and the builtin – SVR2 shell (1984) • Built-ins , , – SVR2 shell (1984) • Source code de-ALGOL68-ized – SVR2 shell (1984) • Modern "" – SVR3 shell (1986) • Built-in – SVR3 shell (1986) • Cleaned up parameter handling allows recursively callable functions – SVR3 shell (1986) • 8-bit clean – SVR3 shell (1986) • Job control – SVR4 shell (1989) • Multi-byte support – SVR4 shell (1989) ==Variants==