World Library  
Flag as Inappropriate
Email this Article

Bourne shell

Article Id: WHEBN0000092839
Reproduction Date:

Title: Bourne shell  
Author: World Heritage Encyclopedia
Language: English
Subject: Shebang (Unix), Unix shell, Cdist, Less-than sign, AWK
Collection: 1977 Software, Posix, Scripting Languages, Text-Oriented Programming Languages, Unix Shells, Unix Sus2008 Utilities
Publisher: World Heritage Encyclopedia

Bourne shell

Bourne shell
Bourne shell interaction on Version 7 Unix
Original author(s) Stephen Bourne
Initial release 1977 (1977)
Operating system Unix
Type Unix shell
License [under discussion]

The Bourne shell (sh) is a shell, or command-line interpreter, for computer operating systems.

The Bourne shell was the default Unix shell of Unix Version 7. 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.


  • History 1
    • Origins 1.1
    • Features of the original version 1.2
    • Features introduced after 1979 1.3
  • Relationship to other shells 2
    • C shell 2.1
    • Korn shell 2.2
    • Almquist shells 2.3
    • Other shells 2.4
  • Usage 3
  • See also 4
  • References 5
  • External links 6


Version 7 Unix: the original Bourne shell manual page. PDP-11 simulation with SIMH


First appearing in Version 7 Unix,[1] the Bourne shell superseded the Mashey shell.

Among the primary goals were:[2]

Features of the original version

Features of the UNIX Version 7 Bourne shell include:

  • Scripts can be invoked as commands by using their filename
  • May be used interactively or non-interactively
  • Allow 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, quotation facilities, and functions.
  • 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 back quotes: `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.
  • "case ~ in ~ esac" selection mechanism, primarily intended to assist argument parsing.
  • sh provided support for environment variables using keyword parameters and exportable variables.
  • It 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[1] 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[3] 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.[4]

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.[5]

Features of the Bourne shell versions since 1979 include:[6]

  • Built-in test command – System III shell (1981)
  • # as comment character – System III shell (1981)
  • Colon in parameter substitutions "${parameter:=word}" – System III shell (1981)
  • Functions and the return builtin – SVR2 shell (1984)
  • Built-ins unset, echo, type – SVR2 shell (1984)
  • Source code de-ALGOL68-ized – SVR2 shell (1984)
  • Modern "$@" – SVR3 shell (1986)
  • Built-in getopts – 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)

Relationship to other shells

C shell

Bill Joy, the author of the C shell, criticized the Bourne shell as being unfriendly for interactive use,[7] 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,[8] and Tom Christiansen also criticized C shell as being unsuitable for scripting and programming.[9]

Korn shell

Interaction with pdksh in OpenBSD (default 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. There is also a clone of ksh88 known as pdksh, and this is the default shell for all users of OpenBSD.

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 much faster execution of standard sh scripts with a smaller memory footprint than its more common 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. Bash incorporates features from the Bourne shell, csh, and ksh. Bash is the default shell for OS X, Cygwin, and most Linux distributions.

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.


The Bourne shell was once standard on all branded Unix systems, although historically BSD-based systems had many scripts written in csh. Bourne shell scripts can typically be run with Bash or dash on GNU/Linux or other Unix-like systems.

On many Linux systems, /bin/sh is a symbolic or hard link to Bash. However, for efficiency, some Linux systems (such as Debian and Ubuntu) link /bin/sh to Debian Almquist shell|dash instead.

See also


  1. ^ a b
  2. ^ "The A-Z of Programming Languages: Bourne shell, or sh" March 2009, Computerworld
  3. ^
  4. ^
  5. ^ Bourne Shell release testing script from Sven Mascheck
  6. ^ History of the Bourne Shell family
  7. ^ An Introduction to the C shell by Bill Joy.
  8. ^
  9. ^

External links

  • UNIX Shell Script Tutorials & Reference
  • The individual members of "The Traditional Bourne Shell Family"
  • Characteristical common properties of the traditional Bourne shells"
  • Historical C source code for the Bourne shell using mac.h macros from 1979
  • Original Bourne Shell documentation from 1978
  • A port of the "heirloom" SVR4 Bourne shell from OpenSolaris to other Unix-like systems
  • Bourne Shell Tutorial (syntax)
  • faqs shell differences
  • Howard Dahdah, The A–Z of Programming Languages: Bourne shell, or sh — An in-depth interview with Steve Bourne, creator of the Bourne shell, or sh, Computerworld, 5 March 2009.
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.