esc
Anthology / Yagnipedia / sh

sh

The Shell That Started Everything and Then Got Out of the Way
Technology · First observed 1979 (Stephen Bourne, Bell Labs — Version 7 Unix — a shell so foundational that every shell since has been either an extension of it or a reaction to it) · Severity: Foundational — the shell equivalent of the wheel, which is to say: invented once, correctly, and still rolling

sh is the Bourne shell, written by Stephen Bourne at Bell Labs in 1979 for Version 7 Unix. It is the shell. Not a shell. The shell. Every shell that came after — Bash, zsh, fish, Nushell, even PowerShell in its confused way — exists in relation to sh: either extending it, replacing it, or pretending it doesn’t exist while quietly implementing most of its syntax.

sh is the POSIX standard for shell scripting. A script that begins with #!/bin/sh will run on every Unix-like system on earth. This has been true since 1979. This will be true after the frameworks are gone.

“The dollar sign. The cursor. The blinking. That is the entire interface. That is sufficient. That has always been sufficient.”
The Lizard, who has not changed the prompt

The Language

sh introduced the shell scripting language that the world still uses. Pipes (|), redirections (>, <, >>), variables ($VAR), control flow (if, while, for, case), command substitution (`command`), and the pipeline philosophy: small programs, connected by pipes, each doing one thing.

This was not just a command interpreter. This was a programming language whose programs were other programs. The shell script does not compute. The shell script orchestrates. It calls grep, sed, awk, sort, cut, and combines their output into something none of them could produce alone.

The Unix philosophy — write programs that do one thing well, write programs that work together — is not a philosophy that exists in the abstract. It exists in sh. sh is the glue. sh is the language in which the philosophy executes.

“sh is not a programming language. sh is the language you use to connect programming languages. This is a more important job.”
The Lizard, on the hierarchy of languages

The Prompt

The default sh prompt is $. A dollar sign. Nothing else.

No username. No hostname. No working directory. No git branch. No kubernetes context. No battery indicator. No emoji. No colour gradient. No powerline fonts. No nerd fonts. No oh-my-anything.

A dollar sign and a cursor. The shell is ready. The shell does not need to tell you where you are, because you already know where you are, and if you don’t, you can type pwd, and the shell will tell you, and then it will return to $, because the shell’s job is not to decorate the prompt, the shell’s job is to run commands.

POSIX

sh is the POSIX shell standard. This means that any script written to the POSIX specification will run on any POSIX-compliant system — Linux, macOS, FreeBSD, AIX, Solaris, any Unix, any Unix-like, any system that respects the standard.

This is the superpower that no other shell has. Bash scripts break on systems that don’t have Bash. zsh scripts break on systems that don’t have zsh. fish scripts break on everything that isn’t fish. sh scripts run everywhere, because sh is everywhere, because POSIX requires it, and POSIX is the law.

The developer who writes #!/bin/sh instead of #!/bin/bash has made a choice. The choice is: this script will outlive me, outlive the distribution, outlive the operating system, and run on a machine that doesn’t exist yet. This is the choice that sh enables and that every other shell merely approximates.

Measured Characteristics

Year created:                            1979
Creator:                                 Stephen Bourne (Bell Labs)
Standard:                                POSIX (the only shell that is the standard)
Default prompt:                          $ (nothing else needed)
Portability:                             every Unix-like system since 1979
Features:                                pipes, redirects, variables, control flow, command substitution
Features it doesn't have:                everything added by Bash, zsh, fish (and doesn't need)
Scripts beginning with #!/bin/sh:        billions (and counting)
Systems where #!/bin/sh works:           all of them
The philosophy:                          connect small programs with pipes
The prompt:                              $ (the Lizard has not changed it)

See Also