ArticleslgStudy

computer science

Bourne shell

Bourne shell is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Bourne shell rather than just read about it. In short: The Bourne shell (sh) is a shell command-line interpreter for computer operating systems. It first appeared on Version 7 Unix, as its default shell.

Bourne shell — main illustration
Bourne shell — illustration

Key takeaways

  • Bourne shell belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Bourne shell to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Bourne shell from memory before moving on to harder problems.

Reference excerpt

The Bourne shell (sh) is a shell command-line interpreter for computer operating systems. It first appeared on Version 7 Unix, as its default shell. 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. The Bourne shell was once standard on all branded Unix systems, although historically BSD-based systems had many scripts written in csh. As the basis of POSIX sh syntax, Bourne shell scripts can typically be run with Bash or dash on Linux or other Unix-like systems; Bash itself is a free clone of Bourne.

History

Origins Work on the Bourne shell initially started in 1976. Developed by Stephen Bourne at Bell Labs, it was a replacement for the Thompson shell, whose executable file had the same name—sh. The Bourne shell was also preceded by the Mashey shell. Bourne 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 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. Some of the primary goals of the shell were:

To allow shell scripts to be used as filters To provide programmability including control flow 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 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 substitution using backquotes: `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 messages, allowing much greater programmatic control during scripting by keeping error messages separate from data.

Influence from Algol 68C Stephen Bourne's coding style was influenced by his experience with the ALGOL 68C compiler 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 ~ then ~ 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 to give the C source code an ALGOL 68 flavor.

The resulting dialect of C has been nicknamed "Bournegol". A sample of "Bournegol" from cmd.c:

These macros (along with the finger 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, System III, 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 test command – System III shell (1981) # as comment character – System III shell (1981) Colon in parameter substitutions "${parameter:=word}" – System III shell (1981) continue with argument – System III shell (1981) cat <<-EOF for indented here documents – 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)

Variants

DMERT shell 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 in Naperville, Illinois uses a 1978 snapshot of Bourne Shell "VERSION sys137 DATE 1978 Oct 12 22:39:57". The DMERT shell runs on 3B21D computers still in use in the telecommunications industry.

Korn 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. 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

… excerpt ends here. Continue reading the full article.

Illustrations

Bourne shell illustration
Bourne shell: Version 7 Unix: the original Bourne shell manual page. PDP-11 simulation with SIMH
Version 7 Unix: the original Bourne shell manual page. PDP-11 simulation with SIMH
Bourne shell: Interaction with pdksh in OpenBSD (default shell)
Interaction with pdksh in OpenBSD (default shell)

Worked examples

Example 1 — a first encounter with Bourne shell

Start with the simplest possible case. Write down what Bourne shell claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Bourne shell before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Bourne shell ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Bourne shell

In research
Bourne shell appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Bourne shell in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Bourne shell is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1979 software, Programming languages standardized by POSIX, Scripting languages, so understanding it makes those chapters shorter.
In everyday life
Look for Bourne shell outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Bourne shell” →

How to study Bourne shell in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Bourne shell means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Bourne shell out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Bourne shell in simple terms?

The Bourne shell (sh) is a shell command-line interpreter for computer operating systems. It first appeared on Version 7 Unix, as its default shell.

Why does Bourne shell matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Bourne shell?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Bourne shell.

Tags

  • 1979 software
  • Programming languages standardized by POSIX
  • Scripting languages
  • Text-oriented programming languages
  • Unix shells

Keep exploring