Shell's colon operator: a null-command with hidden power
Original: A shell colon does nothing. Use it anyway
Why This Matters
Highlights underused POSIX shell features that can simplify script validation and configuration with minimal syntax.
Developer Filip Roséen published an article on July 23, 2026 explaining practical uses of the shell colon (:) — the POSIX null-command dating back to the 1971 Thompson shell — for argument validation, default-setting, file truncation, and trap handling in shell scripts.
Filip Roséen's article details how the shell colon (:), formally the null-command, evaluates its arguments and discards the result — making it a surprisingly versatile tool. Combined with POSIX parameter expansion syntax ${name:?diagnostic}, a single line like : "${1:?missing argument, aborting.}" replaces a multi-line if-statement for mandatory argument checks, printing a diagnostic to stderr and exiting with a non-zero status when the variable is unset or empty. The colon also pairs with :=, allowing default variable assignment without accidentally executing the result as a command: : "${DATA_DIR:=/var/data}". Beyond variable handling, the article highlights file operations — : > error.log truncates a file, and : >> result.json tests write permissions — as well as using : as a required no-op command body in trap : INT or if/then blocks. Roséen traces the colon's history to Unix's 1971 Thompson shell, where it originally served as a label marker and the first comment syntax. The article concludes with FAQ responses addressing why the null-command is necessary for these expansions to work correctly under set -u and similar strict-mode flags.