HOME

TheInfoList



OR:

The Bourne shell (sh) is a
shell Shell may refer to: Architecture and design * Shell (structure), a thin structure ** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses ** Thin-shell structure Science Biology * Seashell, a hard o ...
command-line interpreter A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
for computer
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also i ...
s. The Bourne shell was the default
shell Shell may refer to: Architecture and design * Shell (structure), a thin structure ** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses ** Thin-shell structure Science Biology * Seashell, a hard o ...
for
Version 7 Unix Seventh Edition Unix, also called Version 7 Unix, Version 7 or just V7, was an important early release of the Unix operating system. V7, released in 1979, was the last Bell Laboratories release to see widespread distribution before the commercial ...
.
Unix-like A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
systems continue to have /bin/sh—which will be the Bourne shell, or a
symbolic link In computing, a symbolic link (also symlink or soft link) is a file whose purpose is to point to a file or directory (called the "target") by specifying a path thereto. Symbolic links are supported by POSIX and by most Unix-like operating syste ...
or hard link to a compatible shell—even when other shells are used by most users. Developed by Stephen Bourne at
Bell Labs Nokia Bell Labs, originally named Bell Telephone Laboratories (1925–1984), then AT&T Bell Laboratories (1984–1996) and Bell Labs Innovations (1996–2007), is an American industrial Research and development, research and scientific developm ...
, it was a replacement for the
Thompson shell The Thompson shell was the first Unix shell, introduced in the first version of Unix in 1971, and was written by Ken Thompson. It was a simple command interpreter, not designed for scripting, but nonetheless introduced several innovative featur ...
, 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 a
scripting language A scripting language or script language is a programming language that is used to manipulate, customize, and automate the facilities of an existing system. Scripting languages are usually interpreted at runtime rather than compiled. A scripting ...
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 Brian Wilson Kernighan (; born 1942) is a Canadian computer scientist. He worked at Bell Labs and contributed to the development of Unix alongside Unix creators Ken Thompson and Dennis Ritchie. Kernighan's name became widely known through co- ...
and
Rob Pike Robert "Rob" Pike (born 1956) is a Canadian programmer and author. He is best known for his work on the Go (programming language), Go programming language and at Bell Labs, where he was a member of the Unix team and was involved in the creation o ...
—the first commercially published book that presented the shell as a programming language in a tutorial form.


History


Origins

Work on the Bourne shell initially started in 1976. First appearing in
Version 7 Unix Seventh Edition Unix, also called Version 7 Unix, Version 7 or just V7, was an important early release of the Unix operating system. V7, released in 1979, was the last Bell Laboratories release to see widespread distribution before the commercial ...
, the Bourne shell superseded the Mashey shell. Some of the primary goals of the shell were: * To allow shell scripts to be used as filters. * To provide programmability including
control flow In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an ''im ...
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, 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 In computing, command substitution is a facility that allows a command to be run and its output to be pasted back on the command line as arguments to another command. Command substitution first appeared in the Bourne shell, introduced with Version ...
using
backquotes The backtick is a typographical mark used mainly in computing. It is also known as backquote, grave, or grave accent. The character was designed for typewriters to add a grave accent to a (lower-case) base letter, by overtyping it atop that let ...
: `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 message An error message is information displayed when an unforeseen occurs, usually on a computer or other device. On modern operating systems with graphical user interfaces, error messages are often displayed using dialog boxes. Error messages are use ...
s, 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 ALGOL 68C is an imperative computer programming language, a dialect of ALGOL 68, that was developed by Stephen R. Bourne and Michael Guy to program the Cambridge Algebra System (CAMAL). The initial compiler was written in the Princeton Syntax ...
compiler that he had been working on at
Cambridge University The University of Cambridge is a Public university, public collegiate university, collegiate research university in Cambridge, England. Founded in 1209 and granted a royal charter by Henry III of England, Henry III in 1231, Cambridge is the world' ...
. In addition to the style in which the program was written, Bourne reused portions of
ALGOL 68 ALGOL 68 (short for ''Algorithmic Language 1968'') is an imperative programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously d ...
'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 Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, an ...
Bourne shell syntax. Moreover, – although the v7 shell is written in C – Bourne took advantage of some macros to give the C
source code In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the w ...
an ALGOL 68 flavor. These macros (along with the
finger A finger is a limb of the body and a type of digit, an organ of manipulation and sensation found in the hands of most of the Tetrapods, so also with humans and other primates. Most land vertebrates have five fingers ( Pentadactyly). Chambers ...
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, 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: * Built-in command – System III shell (1981) * # as comment character – System III shell (1981) * Colon in parameter substitutions "$" – 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


DMERT shell

Duplex Multi-Environment Real-Time (
DMERT Multi-Environment Real-Time (MERT), later renamed UNIX Real-Time (UNIX-RT), is a hybrid time-sharing and real-time operating system developed in the 1970s at Bell Labs for use in embedded minicomputers (especially PDP-11s). A version named Dup ...
) is a hybrid time-sharing/real-time operating system developed in the 1970s at Bell Labs Indian Hill location in
Naperville, Illinois Naperville ( ) is a city in DuPage County, Illinois, DuPage and Will County, Illinois, Will counties in the U.S. state of Illinois. It is in the Chicago metro area, west of the city. Naperville was founded in 1831 by Joseph Naper. The city was ...
uses a 1978 snapshot of Bourne Shell "VERSION sys137 DATE 1978 Oct 12 22:39:57". The DMERT shell runs on
3B21D The 3B series computers are a line of minicomputers produced from the late 1970s by AT&T Computer Systems' Western Electric subsidiary for use with the company's UNIX operating system. The line primarily consists of the models 3B20, 3B5, 3B15, 3 ...
computers still in use in the telecommunications industry.


Korn shell

The
Korn shell KornShell (ksh) is a Unix shell which was developed by David Korn at Bell Labs in the early 1980s and announced at USENIX on July 14, 1983. The initial development was based on Bourne shell source code. Other early contributors were Bell ...
(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 The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of th ...
. 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 The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming inter ...
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.


Schily Bourne Shell

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


Relationship to other shells


C shell

Bill Joy William Nelson Joy (born November 8, 1954) is an American computer engineer and venture capitalist. He co-founded Sun Microsystems in 1982 along with Scott McNealy, Vinod Khosla, and Andy Bechtolsheim, and served as Chief Scientist and CTO at ...
, the author of the
C shell The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of th ...
, 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 BSD licenses are a family of permissive free software licenses, imposing minimal restrictions on the use and distribution of covered software. This is in contrast to copyleft licenses, which have share-alike requirements. The original BSD lice ...
, 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 Almquist shell (also known as A Shell, ash and sh) is a lightweight Unix shell originally written by Kenneth Almquist in the late 1980s. Initially a clone of the System V.4 variant of the Bourne shell, it replaced the original Bourne shell in t ...
, 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 developed in 1989 for the
GNU project The GNU Project () is a free software, mass collaboration project announced by Richard Stallman on September 27, 1983. Its goal is to give computer users freedom and control in their use of their computers and computing devices by collaborat ...
and incorporates features from the Bourne shell, csh, and ksh. It is meant to be POSIX-compliant. * rc was created at
Bell Labs Nokia Bell Labs, originally named Bell Telephone Laboratories (1925–1984), then AT&T Bell Laboratories (1984–1996) and Bell Labs Innovations (1996–2007), is an American industrial Research and development, research and scientific developm ...
by
Tom Duff Tom or TOM may refer to: * Tom (given name), a diminutive of Thomas or Tomás or an independent Aramaic given name (and a list of people with the name) Characters * Tom Anderson, a character in '' Beavis and Butt-Head'' * Tom Beck, a character ...
as a replacement for sh for Version 10 Unix. It is the default shell for
Plan 9 from Bell Labs Plan 9 from Bell Labs is a distributed operating system which originated from the Computing Science Research Center (CSRC) at Bell Labs in the mid-1980s and built on UNIX concepts first developed there in the late 1960s. Since 2000, Plan 9 has be ...
. It has been ported to UNIX as part of
Plan 9 from User Space Plan 9 from User Space (also plan9port or p9p) is a port of many Plan 9 from Bell Labs libraries and applications to Unix-like operating systems. Currently it has been tested on a variety of operating systems including: Linux, macOS, FreeBSD, Net ...
. *
Z shell The Z shell (Zsh) is a Unix shell that can be used as an interactive login shell and as a command interpreter for shell scripting. Zsh is an extended Bourne shell with many improvements, including some features of Bash, ksh, and tcsh. History ...
, developed by Paul Falstad in 1990, is an extended Bourne shell with a large number of improvements, including some features of Bash, ksh, and
tcsh tcsh ( “tee-see-shell”, “tee-shell”, or as “tee see ess aitch”, tcsh) is a Unix shell based on and backward compatible with the C shell (csh). Shell It is essentially the C shell with programmable command-line completion, command ...
.


Usage

The Bourne shell was once standard on all branded
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, an ...
systems, although historically BSD-based systems had many scripts written in csh. As the basis of
POSIX The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming inter ...
sh syntax, Bourne shell scripts can typically be run with Bash or
dash The dash is a punctuation mark consisting of a long horizontal line. It is similar in appearance to the hyphen but is longer and sometimes higher from the baseline. The most common versions are the endash , generally longer than the hyphen ...
on
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, w ...
or other
Unix-like A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
systems.


See also

* Comparison of command shells *
Unix shell A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating syste ...


References


External links


The individual members of "The Traditional Bourne Shell Family"


* ttp://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh Historical C source code for the Bourne shell using mac.h macros from 1979
Original Bourne Shell documentation from 1978


* ttps://web.archive.org/web/20191030202653/http://www.unix.org/whitepapers/shdiffs.html Migrating from the System V (SVR4) Shell to the POSIX Shell
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. {{DEFAULTSORT:Bourne Shell 1979 software POSIX Scripting languages Text-oriented programming languages Unix shells Unix SUS2008 utilities de:Unix-Shell#Die Bourne-Shell