A command interpreter becomes a programming language
Designed by Stephen Bourne at Bell Laboratories in Murray Hill, New Jersey, the Bourne shell is both a UNIX command interpreter and a language for combining commands. It received a systematic description in The Bell System Technical Journal in 1978 and became the new sh supplied with Seventh Edition UNIX in 1979. Commands entered interactively and commands executed from files share their principal syntax.
Bourne’s design drew on Ken Thompson’s early UNIX shell and the Programmer’s Workbench, or PWB/UNIX, shell, adding more complete control structures. Dennis Ritchie and John Mashey participated in the design discussions. The aim was to keep terminal input concise while allowing users to write frequently repeated operations as command procedures with arguments, conditional branches and loops.
Connecting existing programs into a workflow
A simple command consists of a command name and arguments. The shell locates the program, establishes its execution environment and waits for it to finish. An ampersand at the end runs the program in the background, allowing the user to enter further commands. Redirection connects input or output to a file instead of the terminal; the invoked program continues to read and write through standard input and standard output.
A pipeline connects one program’s output to the next program’s input. For example, in an ordinary text log, grep error log | sort selects lines containing error and then sorts them. The shell connects the two processes, while grep performs selection and sort performs ordering. Users can recombine existing tools without writing a specialized program for every sequence of operations.
Arguments make command files reusable
Commands can be entered line by line or saved in a file invoked with sh followed by its filename. Scripts receive values through positional parameters: $1 refers to the first argument, and $# gives the number of arguments. The same procedure can therefore process different files or search terms. A command file with execute permission can also be used much like an ordinary program.
String variables hold names, paths and options. Command substitution turns one command’s output into arguments for another. The shell expands filename patterns, such as an asterisk matching a group of filenames. Quotation determines which characters retain their literal meaning and which undergo substitution, so filenames containing spaces and wildcards intended as ordinary text require suitable quoting.
Exit status determines the next step
The Bourne shell incorporates structures such as if, case, for and while directly into the interpreter. Conditions depend on a command’s exit status, conventionally zero for success and nonzero for failure. The test command can examine strings, numeric relationships and file properties. Flow control and external programs’ results can thus work together in the same command language.
A reporting script, for example, can first check whether its input file exists and then sort it, or print an explanation if the file is missing. The for structure applies an operation successively to an argument list, while case selects branches by pattern. These structures allow scripts to handle missing arguments, alternative options and failed operations, rather than simply execute commands in sequence.
Environment, login configuration and signals
A search path specifies where commands are sought and in what order. The .profile file in a user’s home directory holds settings executed at login. Variables marked export become available to newly started commands. Changes a child process makes to its own variables generally do not change its parent’s variables. The command language organizes operations and configures the environment seen by each one.
A here document places text intended as command input directly in the script, reducing the need for separate files. The trap facility lets a script perform cleanup when it receives certain signals, such as removing temporary files before exiting. These features extend command procedures’ expressive range, making input, environment and abnormal termination part of their program structure.
Its place in Seventh Edition UNIX
The Seventh Edition summary lists the new sh alongside Fortran 77, text processing, program construction and improvements to system portability. It highlights string variables, signal handling, structured programming, user configuration and a configurable search path. The Bourne shell spread as part of a complete operating-system toolset, serving terminal work, software development and routine batch processing.
Bourne’s accompanying manual moves from simple commands to arguments, control flow and advanced usage, with practical command procedures written in the shell. It presents a division of work: independent programs perform specific calculations or text operations, while the shell selects, connects and schedules them. Seventh Edition’s significance in 1979 was the inclusion of this fuller command programming interface in the system distribution; its public design description had appeared the previous year.