Original author(s) Type Unix shell | Operating system | |
![]() | ||
Initial release 1977; 40 years ago (1977) |
The Bourne shell (sh) is a shell, or command-line interpreter, for computer operating systems.
Contents
- Origins
- Features of the original version
- Features introduced after 1979
- DMERT shell
- Korn shell
- C shell
- Almquist shells
- Other shells
- Usage
- References
The Bourne shell was the default shell for Version 7 Unix. Most Unix-like systems continue to have /bin/sh—which will be the Bourne shell, or a symbolic link or hard link to a compatible shell—even when other shells are used by most users.
Developed by Stephen Bourne at Bell Labs, it was a replacement for the Thompson shell, whose executable file had the same name—sh. It was released in 1977 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.
Origins
Work on the Bourne shell initially started in 1976. First appearing in Version 7 Unix, the Bourne shell superseded the Mashey shell.
Some of the primary goals of the shell were:
Features of the original version
Features of the Version 7 UNIX Bourne shell include:
`command`
.<<
to embed a block of input text within a script.for ~ do ~ done
" loops, in particular the use of $*
to loop over arguments.case ~ in ~ esac
" selection mechanism, primarily intended to assist argument parsing.sh
provided support for environment variables using keyword parameters and exportable variables.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 ~ 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 IOCCC – International Obfuscated C Code Contest.
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, SystemIII, 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:
test
command – System III shell (1981)continue
with argument – System III shell (1981)cat <<-EOF
for indented here documents – System III shell (1981)return
builtin – SVR2 shell (1984)unset
, echo
, type
– SVR2 shell (1984)$@
" – SVR3 shell (1986)getopts
– SVR3 shell (1986)DMERT shell
Duplex Multi-Environment Real-Time (DMERT) is a hybrid time-sharing/real-time operating system developed in the 1970s at Bell Labs Indian Hill location in Naperville, Illinois uses a 1978 snapshot of Bourne Shell "VERSION sys137 DATE 1978 Oct 12 22:39:57". The DMERT shell runs on 3B21D computers still in use in the telecommunications industry.
Korn shell
The Korn shell (ksh) written by David Korn based on the original Bourne Shell source code, was a middle road between the Bourne shell and the C shell. Its syntax was chiefly drawn from the Bourne shell, while its job control features resembled those of the C shell. The functionality of the original Korn Shell (known as ksh88 from the year of its introduction) was used as a basis for the POSIX shell standard. A newer version, ksh93, has been open source since 2000 and is used on some Linux distributions. A clone of ksh88 known as pdksh is the default shell in OpenBSD.
C shell
Bill Joy, the author of the C shell, criticized the Bourne shell as being unfriendly for interactive use, a task for which Stephen Bourne himself acknowledged C shell's superiority. Bourne stated, however, that his shell was superior for scripting and was available on any Unix system, and Tom Christiansen also criticized C shell as being unsuitable for scripting and programming.
Almquist shells
Due to copyright issues surrounding the Bourne Shell as it was used in historic CSRG BSD releases, Kenneth Almquist developed a clone of the Bourne Shell, known by some as the Almquist shell and available under the BSD license, which is in use today on some BSD descendants and in low-memory situations. The Almquist Shell was ported to Linux, and the port renamed the Debian Almquist shell, or dash. This shell provides faster execution of standard sh (and POSIX-standard sh, in modern descendants) scripts with a smaller memory footprint than its counterpart, Bash. Its use tends to expose bashisms – bash-centric assumptions made in scripts meant to run on sh.
Other shells
Bash (the Bourne-Again shell) was later developed for the GNU project and incorporates features from the Bourne shell, csh, and ksh. It is meant to be POSIX-compliant.
rc was created at Bell Labs by Tom Duff as a replacement for sh for Version 10 Unix. It is the default shell for Plan 9 from Bell Labs. It has been ported to UNIX as part of Plan 9 from User Space.
Usage
The Bourne shell was once standard on all branded Unix systems, although historically BSD-based systems had many scripts written in csh. As the basis of POSIX sh syntax, Bourne shell scripts can typically be run with Bash or dash on GNU/Linux or other Unix-like systems.