HeadlinesBriefing favicon HeadlinesBriefing.com

Why POSIX isn’t a shell and what that means for scripts

Hacker News •
×

When developers claim “write it in POSIX shell for portability,” they cite a specification, not an interpreter. The actual runtime is bash, dash, ash, ksh, yash, or other shells, each with gaps and extensions. A simple test—`echo "C:\new"`—shows bash and several shells echo the literal string, while dash on Debian, Ubuntu and Alpine rewrites the backslash as a newline on typical Linux installations.

The discrepancy stems from the standard itself: POSIX leaves echo’s handling of backslash escapes implementation‑defined and recommends printf for reliable output. Consequently, “POSIX‑compliant echo” is not a reproducible behavior. Alexandre Gomes Gaigalas built shell‑docs, a cross‑shell reference that runs each example on 14 shells, recording divergences such as arithmetic errors, [[ ]] support, and local variable scoping. Some shells still lack full POSIX support.

The tool also tracks which shell version ships with major distributions: dash 0.5.12 on Ubuntu 24.04, bash 3.2.57 on macOS, busybox ash on Alpine, and ksh93 on some enterprise Linux releases. By validating scripts across this matrix, developers can honestly claim “portable” rather than assuming compatibility. In practice, specifying #!/bin/bash or rigorously testing #!/bin/sh yields reliable results.