The POSIX Shell (Shell Command Language)

The POSIX shell is not a program but a specification: the Shell Command Language defined in Chapter 2 of the Shell and Utilities volume of IEEE Std 1003.1, the Portable Operating System Interface (POSIX) standard, jointly maintained by the IEEE and The Open Group. The current Open Group Base Specifications publication, Issue 7 (IEEE Std 1003.1-2017, also called POSIX.1-2017), states the requirements that the sh utility and conforming shells must satisfy so that shell scripts behave identically across different Unix and Unix-like systems.

The specification arose because, although the Bourne shell had become the de facto Unix standard, real implementations diverged in subtle and not-so-subtle ways. By writing down the grammar precisely, POSIX gave script authors a portable target. The document defines the shell’s token recognition and quoting rules, parameter and variable expansion, command substitution, arithmetic expansion, pathname expansion (globbing), redirection operators, pipelines, and the control-flow compound commands: for, case, if, while, and until. It also specifies how the shell sets exit status, handles signals, and reads its environment.

Crucially, the standard is built on the Bourne shell rather than the interactive-oriented C shell. A POSIX-conformant script uses only the features the document guarantees and avoids extensions particular to any one shell. This is why careful authors write scripts to /bin/sh and restrict themselves to POSIX constructs: such scripts run unchanged under Bash in POSIX mode, under the lightweight Dash that serves as /bin/sh on many Debian-derived systems, under the Korn shell, and under the native sh of commercial Unix variants.

The specification deliberately stops short of the conveniences that distinguish interactive shells. Features such as command-line editing, associative arrays, advanced pattern matching, and programmable completion are left to individual implementations; they are useful but not portable, and POSIX is concerned with portability. The line between “POSIX shell” and a given shell’s own dialect is therefore an important practical boundary that every shell programmer eventually learns.

Because the Open Group publishes the standard openly online, anyone can consult the exact normative text. That accessibility, combined with the wide adoption of POSIX conformance as a goal by shell implementers, has made the Shell Command Language one of the most quietly important standards in computing: it is the contract that lets a script written on one Unix-like system run on nearly any other, decades and platforms apart.