Bourne shell
Encyclopedia
The Bourne shell, or sh, was the default Unix shell
Unix shell
A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems...

 of Unix Version 7
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 commercialization of Unix by AT&T in the early 1980s...

 and most Unix-like systems continue to have /bin/sh - which will be the Bourne shell, or a symbolic link
Symbolic link
In computing, a symbolic link is a special type of file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution. Symbolic links were already present by 1978 in mini-computer operating systems from DEC and Data...

 or hard link
Hard link
In computing, a hard link is a directory entry that associates a name with a file on a file system. . The term is used in file systems which allow multiple hard links to be created for the same file. This has the effect of creating multiple names for the same file, causing an aliasing effect: e.g...

 to a compatible shell - even when more modern shells are used by most users.

Developed by Stephen Bourne at AT&T
AT&T
AT&T Inc. is an American multinational telecommunications corporation headquartered in Whitacre Tower, Dallas, Texas, United States. It is the largest provider of mobile telephony and fixed telephony in the United States, and is also a provider of broadband and subscription television services...

 Bell Laboratories, it was a replacement for the Thompson shell
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 features to the command line interface and led to the...

, whose executable file had the same name, sh. It was released in 1977 in the Version 7 Unix
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 commercialization of Unix by AT&T in the early 1980s...

 release distributed to colleges and universities. Although it is used as an interactive command interpreter, it was always intended as a scripting language and contains all the features that are commonly considered to produce structured programs.

It gained popularity with the publication of The UNIX Programming Environment
The Unix Programming Environment
The Unix Programming Environment, first published in 1984 by Prentice Hall, is a book written by Brian W. Kernighan and Rob Pike, both of Bell Labs and considered an important and early document of the Unix operating system....

 by Brian W. Kernighan and Rob Pike — the first commercially published book that presented the shell as a programming language in a tutorial form.

Origins

The shell was designed as a replacement for the original Thompson shell
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 features to the command line interface and led to the...

.

Among the primary goals were:
  • To allow shell script
    Shell script
    A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language...

    s to be used as filters.
  • To provide programmability including control flow
    Control flow
    In computer science, control flow refers to the order in which the individual statements, instructions, or function calls of an imperative or a declarative program are executed or evaluated....

     and variables
    Variable (programming)
    In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...

    .
  • Control over all input/output file descriptor
    File descriptor
    In computer programming, a file descriptor is an abstract indicator for accessing a file. The term is generally used in POSIX operating systems...

    s.
  • Control over signal handling
    Signal (computing)
    A signal is a limited form of inter-process communication used in Unix, Unix-like, and other POSIX-compliant operating systems. Essentially it is an asynchronous notification sent to a process in order to notify it of an event that occurred. When a signal is sent to a process, the operating system...

     within scripts.
  • No limits on string lengths when interpreting shell scripts.
  • Rationalize and generalize string quoting mechanism.
  • The environment mechanism
    Environment variable
    Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.They can be said in some sense to create the operating environment in which a process runs...

    . This allowed context to be established at startup and provided a way for shell scripts to pass context to sub scripts (processes
    Process (computing)
    In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...

    ) without having to use explicit positional parameters
    Parameter (computer science)
    In computer programming, a parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are called arguments...

    .

Features

Features of the 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
    Command substitution
    In computing, command substitution is a facility originally introduced in the Unix shells that allows a command to be run and its output to be pasted back on the command line as arguments to another command...

    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
File descriptor
In computer programming, a file descriptor is an abstract indicator for accessing a file. The term is generally used in POSIX operating systems...

 2> for error message
Error message
An error message is information displayed when an unexpected condition occurs, usually on a computer or other device. On modern operating systems with graphical user interfaces, error messages are often displayed using dialog boxes...

s, allowing much greater programmatic control during scripting by keeping error messages separate from data.

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
ALGOL 68C
The ALGOL68C computer programming language compiler was developed for the CHAOS OS for the CAP capability computer at Cambridge University in 1971 by Stephen Bourne and Michael Guy as a dialect of ALGOL 68. Other early contributors were Andrew D. Birrell and Ian Walker.The initial compiler was...

 compiler that he had been working on at Cambridge University
University of Cambridge
The University of Cambridge is a public research university located in Cambridge, United Kingdom. It is the second-oldest university in both the United Kingdom and the English-speaking world , and the seventh-oldest globally...

. Notably he reused portions of ALGOL 68
ALGOL 68
ALGOL 68 isan imperative computerprogramming language that was conceived as a successor to theALGOL 60 programming language, designed with the goal of a...

's "if ~ then ~ elif ~ else ~ fi", "case ~ in ~ esac" and "for ~ while ~ do ~ od" (using done instead of od) clauses in the common Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 Bourne shell syntax. Moreover - although the v7 shell is written in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 - Bourne took advantage of some macros to give the C source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

 an ALGOL 68 flavor. These macros (along with the finger
Finger protocol
In computer networking, the Name/Finger protocol and the Finger user information protocol are simple network protocols for the exchange of human-oriented status and user information.-Name/Finger protocol:...

 command distributed in Unix version 4.2BSD) inspired the IOCCC - International Obfuscated C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 Code Contest
.

Criticism

The Bourne shell has been criticized for its shortcomings compared to the C shell
C shell
The C shell is a Unix shell that was created by Bill Joy while a graduate student at University of California, Berkeley in the late 1970s. It has been distributed widely, beginning with the 2BSD release of the BSD Unix system that Joy began distributing in 1978...

.
  • The Bourne shell was not as friendly for interactive use. C shell
    C shell
    The C shell is a Unix shell that was created by Bill Joy while a graduate student at University of California, Berkeley in the late 1970s. It has been distributed widely, beginning with the 2BSD release of the BSD Unix system that Joy began distributing in 1978...

     offered history, aliases, job control and other features that made it faster and easier to use.
  • Even though the rest of the Unix system was written in C, the Bourne shell's grammar
    Formal grammar
    A formal grammar is a set of formation rules for strings in a formal language. The rules describe how to form strings from the language's alphabet that are valid according to the language's syntax...

     looked nothing like C; it looked like ALGOL
    ALGOL
    ALGOL is a family of imperative computer programming languages originally developed in the mid 1950s which greatly influenced many other languages and became the de facto way algorithms were described in textbooks and academic works for almost the next 30 years...

    , instead.
  • It lacked an expression grammar
    Expression (programming)
    An expression in a programming language is a combination of explicit values, constants, variables, operators, and functions that are interpreted according to the particular rules of precedence and of association for a particular programming language, which computes and then produces another value...

    . Even simple arithmetic had to be done using the external test
    Test (Unix)
    test is a command in Unix that evaluates conditional expressions.-Description:The test command evaluates the expression parameter. In some shells , it is actually a shell builtin, even though external version still exists. In the second form of the command, the [ ] must be surrounded by blank...

    and expr
    Expr
    expr is a command line Unix utility which evaluates an expression and outputs the corresponding value. It first appeared in Unix v7 as a standalone program, and was later incorporated into the shell as a built-in command.Syntax: expr ...

    utilities.

Descendants

The Korn shell
Korn shell
The Korn shell is a Unix shell which was developed by David Korn in the early 1980s and announced at USENIX on July 14, 1983. Other early contributors were AT&T Bell Labs developers Mike Veach, who wrote the emacs code, and Pat Sullivan, who wrote the vi code...

 (ksh) written by David Korn, was a middle road between the Bourne shell and the C shell
C shell
The C shell is a Unix shell that was created by Bill Joy while a graduate student at University of California, Berkeley in the late 1970s. It has been distributed widely, beginning with the 2BSD release of the BSD Unix system that Joy began distributing in 1978...

. 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
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

 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.

rc
Rc
rc is the command line interpreter for Version 10 Unix and Plan 9 from Bell Labs operating systems. It resembles the Bourne shell, but its syntax is somewhat simpler. It was created by Tom Duff, who is better known for an unusual C programming language construct called Duff's device.A port of the...

 was created at Bell Labs
Bell Labs
Bell Laboratories is the research and development subsidiary of the French-owned Alcatel-Lucent and previously of the American Telephone & Telegraph Company , half-owned through its Western Electric manufacturing subsidiary.Bell Laboratories operates its...

 by Tom Duff
Tom Duff
Thomas Douglas Selkirk Duff is a computer programmer. He was born in Toronto, Ontario, Canada and grew up in Toronto and Leaside. In 1974 he graduated from the University of Waterloo with a B.Math and, two years later, got an M.Sc...

 as a replacement for sh for Version 10 Unix
Version 10 Unix
Tenth Edition Unix, also known as Version 10 Unix or V10, was the last version of the Research Unix operating system developed and used internally at Bell Labs. "Released" in 1989, it was the successor of V9...

. It is the default shell for Plan 9 from Bell Labs
Plan 9 from Bell Labs
Plan 9 from Bell Labs is a distributed operating system. It was developed primarily for research purposes as the successor to Unix by the Computing Sciences Research Center at Bell Labs between the mid-1980s and 2002...

. It has been ported to UNIX as part of Plan 9 from User Space
Plan 9 from User Space
Plan 9 from User Space is a port of many Plan 9 from Bell Labs libraries and applications to Unix-like operating systems...

.

Bash, also known as the Bourne-Again shell, was later developed for the GNU project
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

 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
Computer Systems Research Group
The Computer Systems Research Group was a research group at the University of California, Berkeley that was dedicated to enhancing AT&T Unix operating system and funded by Defense Advanced Research Projects Agency.- History :...

 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
Debian Almquist shell
The Debian Almquist shell is a Unix shell, much smaller than bash but still aiming at POSIX-compliancy. It requires less disk space but is also less feature-rich.- History :...

, 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
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 systems, although historically BSD-based systems had many scripts written in csh
C shell
The C shell is a Unix shell that was created by Bill Joy while a graduate student at University of California, Berkeley in the late 1970s. It has been distributed widely, beginning with the 2BSD release of the BSD Unix system that Joy began distributing in 1978...

. Bourne shell scripts can typically be run with bash or dash
Debian Almquist shell
The Debian Almquist shell is a Unix shell, much smaller than bash but still aiming at POSIX-compliancy. It requires less disk space but is also less feature-rich.- History :...

 on GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

/Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

 or other Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 systems.

Quotes

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK