Jump to content

Bourne shell

From Wikipedia, the free encyclopedia

Bourne shell
Original author(s)Stephen Bourne
Developer(s)Bell Telephone Laboratories
Initial release1979;45 years ago(1979)
Operating systemUnix
TypeUnix shell
License[under discussion]

TheBourne shell(sh) is ashellcommand-line interpreterfor computeroperating systems.

The Bourne shell was the defaultshellforVersion 7 Unix.Unix-likesystems continue to have/bin/sh—which will be the Bourne shell, or asymbolic linkorhard linkto a compatible shell—even when other shells are used by most users.

Developed byStephen BourneatBell Labs,it was a replacement for theThompson shell,whose executable file had the same name—sh.It 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 ascripting languageand contains most of the features that are commonly considered to produce structured programs.

It gained popularity with the publication ofThe Unix Programming EnvironmentbyBrian KernighanandRob Pike—the first commercially published book that presented the shell as a programming language in a tutorial form.

History

[edit]
Version 7 Unix:the original Bourne shellmanual page.PDP-11simulation withSIMH

Origins

[edit]

Work on the Bourne shell initially started in 1976.[1]First appearing inVersion 7 Unix,[2]the Bourne shell was preceded by theMashey shell.

Some of the primary goals of the shell were:[3]

Features of the original version

[edit]

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 substitutionusingbackquotes:`command`.
  • Here documentsusing<<to embed a block of input text within a script.
  • for ~ do ~ doneloops, in particular the use of$*to loop over arguments, as well asfor ~ in ~ do ~ doneloops for iterating over lists.
  • case ~ in ~ esacselection mechanism, primarily intended to assistargument parsing.
  • shprovided support for environment variables using keyword parameters and exportable variables.
  • Contains strong provisions for controlling input and output and in itsexpression matchingfacilities.

The Bourne shell also was the first to feature the convention of usingfile descriptor2>forerror 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 theALGOL 68Ccompiler[2]that he had been working on atCambridge University.In addition to the style in which the program was written, Bourne reused portions ofALGOL 68'sif~then~elif~then~else~fi,case~in~esacandfor/while~do~od"(usingdoneinstead ofod) clauses in the commonUnixBourne shell syntax. Moreover, – although the v7 shell is written inC– Bourne took advantage of somemacros[4]to give the Csource codean ALGOL 68 flavor. These macros (along with thefingercommand distributed in Unix version4.2BSD) inspired theInternational Obfuscated C Code Contest(IOCCC).[5]

Features introduced after 1979

[edit]

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

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

  • Built-intestcommand – System III shell (1981)
  • # as comment character – System III shell (1981)
  • Colon in parameter substitutions "${parameter:=word}" – System III shell (1981)
  • continuewith argument – System III shell (1981)
  • cat <<-EOFfor indented here documents – System III shell (1981)
  • Functions and thereturnbuiltin – SVR2 shell (1984)
  • Built-insunset,echo,type– SVR2 shell (1984)
  • Source code de-ALGOL68-ized – SVR2 shell (1984)
  • Modern "$@"– SVR3 shell (1986)
  • Built-ingetopts– 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

[edit]

DMERT shell

[edit]

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 inNaperville, Illinoisuses a 1978 snapshot of Bourne Shell "VERSION sys137 DATE 1978 Oct 12 22:39:57".[citation needed]The DMERT shell runs on3B21Dcomputers still in use in the telecommunications industry.[citation needed]

Korn shell

[edit]
Interaction withpdkshinOpenBSD(default shell)

TheKorn shell(ksh) written byDavid Kornbased on the original Bourne Shell source code,[8]was a middle road between the Bourne shell and theC shell.Its syntax was chiefly drawn from the Bourne shell, while itsjob controlfeatures 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 thePOSIXshell standard. A newer version, ksh93, has been open source since 2000 and is used on someLinux distributions.A clone of ksh88 known aspdkshis the default shell in OpenBSD.

Schily Bourne Shell

[edit]

Jörg Schilling's Schily-Tools includes three Bourne Shell derivatives.[9]

Relationship to other shells

[edit]

C shell

[edit]

Bill Joy,the author of theC shell,criticized the Bourne shell as being unfriendly for interactive use,[10]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,[11]andTom Christiansenalso criticized C shell as being unsuitable for scripting and programming.[12]

Almquist shells

[edit]

Due to copyright issues surrounding the Bourne Shell as it was used in historicCSRGBSD releases, Kenneth Almquist developed a clone of the Bourne Shell, known by some as theAlmquist shelland available under theBSD 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 theDebian Almquist shell,or dash. This shell provides faster execution of standardsh(and POSIX-standardsh,in modern descendants) scripts with a smallermemory footprintthan its counterpart, Bash. Its use tends to exposebashisms– bash-centric assumptions made in scripts meant to run on sh.

Other shells

[edit]

Usage

[edit]

The Bourne shell was once standard on all brandedUnixsystems, although historicallyBSD-based systems had many scripts written incsh.As the basis ofPOSIXshsyntax, Bourne shell scripts can typically be run withBashordashonLinuxor otherUnix-likesystems.

See also

[edit]

References

[edit]
  1. ^https:// bsdcan.org/2015/schedule/events/612.en.htmlStephen Bourne Keynote for BSDCan 2015
  2. ^abMcIlroy, M. D.(1987).A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986(PDF)(Technical report). CSTR. Bell Labs. 139.Archived(PDF)from the original on 4 May 2014.
  3. ^"The A-Z of Programming Languages: Bourne shell, or sh".computerworld.au.Archived fromthe originalon 11 January 2010.Retrieved6 March2009.
  4. ^Bourne, Steve(12 January 1979)."mac.h – Macros used by Bourne to structure C like Algol68C".AT&T Corporation.Retrieved9 September2006.
  5. ^Landon Curt Noll;Simon Cooper; Peter Seebach & Leonid A. Broukhis (2004)."The IOCCC FAQ – Q/A: How did the IOCCC get started?".ioccc.org.Retrieved9 September2006.
  6. ^"what shell is this".in-ulm.de.
  7. ^"traditional Bourne shell family / history and development".in-ulm.de.
  8. ^ Korn, David G. (26 October 1994),"ksh - An Extensible High Level Language",Proceedings of the USENIX 1994 Very High Level Languages Symposium,USENIX Association,retrieved5 February2015,Instead of inventing a new script language, we built a form entry system by modifying the Bourne shell, adding built-in commands as necessary.
  9. ^"Schily Bourne Shell - A modern enhanced and POSIX compliant Bourne Shell source maintained by Jörg Schilling".Schily-Tools.
  10. ^An Introduction to the C shellArchived13 July 2018 at theWayback MachinebyBill Joy.[page needed]
  11. ^Bourne, Stephen R. (October 1983)."The Unix Shell".BYTE.p. 187.Retrieved30 January2015.
  12. ^Tom Christiansen (28 September 1995)."Csh Programming Considered Harmful".Retrieved17 February2014.
[edit]