- Bourne shell
The Bourne shell, or sh, was the default
Unix shell of Unix Version 7, and replaced theThompson shell , whose executable file had the same name, sh. It was developed byStephen Bourne , ofAT&T Bell Laboratories , and was released in 1977 in theVersion 7 Unix release distributed to colleges and universities. It remains a popular default shell for Unix accounts. The binary program of the Bourne shell or a compatible program is located at/bin/sh
on mostUnix systems, and is still the default shell for the rootsuperuser on many current Unix implementations.Origins
The shell was designed as a replacement for the original
Thompson shell .Among the primary goals were:
* To allowshell script s to be used as filters.
* To provide programmability includingcontrol flow andvariable s.
* Control over all input/outputfile descriptor s.
* 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.Notable features
Although it is used as an interactive command interpreter, it was always intended as a scripting language. It gained popularity with the publication of
The UNIX Programming Environment byBrian W. Kernighan andRob Pike . This was the first commercially published book that presented the shell as a programming language in a tutorial form.The Bourne shell also was the first to feature the convention of using
file descriptor 2>
forerror message s, allowing much greater programmatic control during scripting by keeping error messages separate from data.Other innovations in this shell included:
* "Command substitution" using back quotes:`command`
.
* "Here document s" 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.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.
Stephen Bourne carried into this shell some aspects of the
ALGOL 68C compiler that he had been working on at Cambridge University. Notably he reused portions ofALGOL 68 's "if ~ then ~ elif ~ else ~ fi
", "case ~ in ~ out ~ esac
" and "for ~ while ~ do ~ od
" clauses in the commonUnix Bourne shell syntax. Moreover - although the v7 shell is written in C - Bourne took advantage of some macros [cite web | url=http://minnie.tuhs.org/UnixTree/V7/usr/src/cmd/sh/mac.h.html|title=mac.h - Macros used by Bourne to structure C like Algol68C |accessmonthday=September 9 |accessyear=2006|author=Bourne, Steve|authorlink=Stephen Bourne|date=1979-01-12 |work= |publisher=AT&T ] to give the Csource code an ALGOL 68 flavor. These macros "co-inspired" the "IOCCC - International Obfuscated C Code Contest" ("Co-inspired" with the finger command as distributed in Unix version4.2BSD ) [cite web |url=http://www.ioccc.org/faq.html|title=The IOCCC FAQ - Q/A: How did the IOCCC get started?|accessmonthday=September 9 | accessyear=2006|author=Landon Curt Noll , Simon Cooper, Peter Seebach and Leonid A. Broukhis|date= 2004|work=|publisher=www.ioccc.org] .Descendants
The
Korn shell (ksh) written byDavid Korn , was a middle road between the Bourne shell and theC shell (which itself was derived from theThompson 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 thePOSIX 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 aspdksh , and this is the default shell for all users of OpenBSD.rc was created atBell Labs byTom Duff as a replacement for sh forVersion 10 Unix . It is the default shell forPlan 9 from Bell Labs . It has been ported to UNIX as part ofPlan 9 from User Space .Bash , also known as the "Bourne-Again shell", was later developed for the GNU project and takes features from the Bourne shell, csh and ksh.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 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 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.Usage
The Bourne shell was once standard on all branded
Unix systems, although historicallyBSD based systems had many scripts written in csh. Bourne shell scripts can typically be run withbash or dash onLinux or otherUnix-like systems.Quotes
quotation|"Nobody really knows what the Bourne shell's grammar is. Even examination of the source code is little help."|
Tom Duff cite web
first=Chet|last=Ramey
title=Bash - the GNU shell (Reflections and Lessons Learned)
url=http://www.wing.rug.nl/info/programs/bash/article.html#6
accessdate=2008-01-15]ee also
*
Comparison of computer shells
*Bash
*rc References
External links
* [http://www.injunea.demon.co.uk/pages/page201.htm UNIX Shell Script Tutorials & Reference]
* [http://steve-parker.org/sh/sh.shtml UNIX/Linux Bourne/Bash Shell Scripting Tutorial]
* [http://www.in-ulm.de/~mascheck/bourne/ The individual members of "The Traditional Bourne Shell Family"]
* [http://minnie.tuhs.org/UnixTree/V7/usr/src/cmd/sh Actual C source code for the Bourne shell using mac.h macros]
* [http://steve-parker.org/sh/bourne.shtml Original Bourne Shell documentation from 1978]
* [http://heirloom.sourceforge.net/sh.html A port of the "heirloom" SVR4 Bourne shell from OpenSolaris to other Unix-like systems]
Wikimedia Foundation. 2010.