Kelly Mears

Shell

The interactive command interpreter, and a programming language with unusually sharp edges.

Systems & Tooling2 min read225 words15 out · 19 in
also calledBashzshCommand line

A shell is the program that interprets typed commands: it expands words, resolves programs, wires their inputs and outputs together, and reports their exit status. It is simultaneously the most-used interface in software work and a programming language with more surprising behavior per line than any other in common use.

The behaviors that produce the most wasted time are worth learning explicitly.

Expansion happens before the program runs. A variable in a command line is substituted by the shell, so a program's own configuration file cannot influence an argument the shell already expanded — which is why a command that reads a port from the environment binds the shell's port and not the one in a local configuration file.

Shells differ. Variable names reserved in one are ordinary in another; a script assigning to a name the shell owns dies on its first line with a one-word error.

Quoting is the perennial hazard, and a pattern that becomes empty after expansion may match everything rather than nothing.

A process matcher can match itself. A wait loop that polls for a pattern present in its own command line never exits — wait on an artifact instead.

Exit status is the shell's only universal signal, and it means "the program returned zero", which frequently is not the same as "the thing you wanted happened". See Vacuous Truth.

See also14

Glob

Wildcard pattern matching over filenames, similar enough to regular expressions to mislead.

Systems & Tooling12 connections

Dotfiles

A tracked repository of personal configuration, making a machine setup reproducible.

Systems & Tooling17 connections

Terminal User Interface

An interface rendered as text in a terminal, and the design conventions that make command-line tools humane.

Graphics & Rendering16 connections

Environment Variable

A named value in a process's environment, inherited by its children — the standard configuration channel.

Systems & Tooling23 connections

Process

A running program with its own memory, environment, and identity.

Systems & Tooling33 connections

Port

The numeric endpoint a network service listens on, and a scarce shared resource on a developer machine.

Systems & Tooling19 connections

Character Encoding

The mapping between characters and bytes, and the source of a specific family of invisible bugs.

Systems & Tooling31 connections

Silent Failure

A failure that produces no signal, so the absence of an error reads as success.

Method73 connections

Ground Truth

The measurement that arbitrates, as opposed to the artifact that merely reports.

Method99 connections

Terminal Multiplexer

A program that runs many terminal sessions inside one window, splits it into panes, and keeps the sessions alive on a server after the connection drops, so long jobs and remote work survive disconnection.

Systems & Tooling10 connections

Command-Line Interface

Operating a computer by typing commands and reading text replies, the interface inherited from teletypes that remains the fastest, most scriptable, and least discoverable way to control software.

Systems & Tooling14 connections

Shebang

The "#!" line at the top of a script that tells the kernel which interpreter should run it, so a text file can be executed like a compiled program, and the portability traps around it.

Systems & Tooling11 connections

Exit Status

The small number every process returns when it ends, zero for success and anything else for failure, and the conventions that let shells, CI systems, and init systems act on it.

Systems & Tooling10 connections

Pseudoterminal

The kernel device pair that lets a terminal window, SSH session, or tmux pane pretend to be a 1970s hardware terminal, and why programs behave differently when they are not attached to one.

Systems & Tooling12 connections

Linked from19