The Shell Colon Does Nothing. You Should Use It Anyway.

TL;DR
The shell colon null command explained: parameter expansion checks, default values, infinite loops and the git rebase trick, plus the HN readability debate.
Last updated: July 26, 2026
Filip Roseen published a deep dive on the shell : (colon) builtin that hit 325 points on Hacker News because it scratches an itch every developer knows: shell scripting is indispensable, but its syntax is full of secrets that only reveal themselves after years of use.
The article at refp.se walks through several ways : - the null command that evaluates its arguments and discards the result - can make scripts tighter and more robust:
- Required argument checking.
: "${1:?missing argument, aborting.}"replaces a four-line if-statement with one line that prints a diagnostic and exits with a non-zero status. - Default value assignment.
: "${DOTFILES_PATH:=$HOME/.dotfiles}"sets a variable to a default if it is unset or empty, without triggering any side effect. - Infinite loops.
while :; do ... doneis the idiomatic way to write a loop that runs until broken from within. - No-op in conditionals. When an
ifbranch needs a placeholder command,:fills the spot without producing output. - File truncation.
: > filetruncates a file to zero length (and creates it if it does not exist), though commenters note that a plain> fileworks the same way without the colon.
The thread reveals that the colon goes back to the 1971 Thompson shell, making it one of the oldest surviving builtins in Unix. Its continued relevance is a testament to the shell's design philosophy: compose small, sharp primitives.
What HN Is Saying#
The discussion at 137 comments is split between appreciation and concern. The most-upvoted themes:
Readability is the fault line. Multiple top comments argue that every colon trick makes scripts harder to read. "Concise != better" is the recurring counterpoint. One commenter writes: "A language feature that needs marketing is against readability" - implying that if : was truly intuitive, nobody would need an article explaining it. Another says "life is way too short to deal with this nightmare of a language and its 50000 footguns for anything longer than a 2 line script."
The git rebase trick wins universal praise. Commenter fphilipe shared that they use : as the sequence.editor for git interactive rebase, allowing auto-squash rebases without editing the todo list. The alias riq = -c sequence.editor=: rebase --interactive was widely appreciated as a genuinely practical use that most developers had not considered.
Parameter expansion is the real hero. The : "${VAR:?error}" pattern drew the most positive responses. Even critics of the article's one-liner style acknowledged that parameter expansion with :? is a legitimate readability and safety gain. Commenter olexsmir shared a real use in dotfiles bootstrap scripts: : "${DOTFILES_PATH:=$HOME/.dotfiles}".
The truncation example is misleading. Commenter jiveturkey pointed out that : > file creates the file if it does not exist, not just truncate it - and that it works identically without the colon. The article could have been clearer on this distinction.
One-liners are a cultural artifact. Several commenters placed the colon tricks in the long tradition of shell golf - clever, technically interesting, but generally counterproductive in team environments where maintainability matters more than concision.
Why This Matters#
The colon debate is a microcosm of a larger tension in developer tooling: elegance versus accessibility. Every shell feature that saves three lines for an expert costs thirty seconds of head-scratching for a newcomer. That trade-off is real, and the HN comments reflect it honestly.
But there is a case for knowing the colon even if you rarely type it. Reading other people's scripts is a daily reality - Dockerfiles, CI configs, build pipelines, deployment hooks. The : "${VAR:?error}" pattern appears in enough production shell scripts that recognizing it saves debugging time. The same goes for while : in init scripts and entrypoints.
The deeper lesson is about good tools being invisible. The colon has survived for 55 years because the shell was built to compose text-processing pipelines from tiny commands. : is the ultimate expression of that philosophy: a command that does nothing, but whose side effects (argument evaluation, parameter expansion) make everything else work.
In the age of terminal-based AI coding agents, understanding the shell's primitives is not an academic exercise. Agents like Claude Code and Codex CLI execute shell commands on your behalf. When an agent writes : "${1:?missing}" in a generated script, knowing what it does - and why it is there - is the difference between trusting the output and blindly accepting it. The same argument applies to other shell idioms that AI agents tend to generate: knowing the tools means knowing when to override them.
For developers who want to be intentional about their shell habits, the colon is worth adding to your vocabulary - not as a daily driver, but as a recognition primitive and an occasional sharp tool.
FAQ#
What does the colon command do in the shell?#
: is the null command. It evaluates its arguments and discards the result, which makes it useful for side effects such as parameter expansion. It goes back to the 1971 Thompson shell.
How do you require an argument in a shell script with the colon?#
: "${1:?missing argument, aborting.}" prints a diagnostic and exits with a non-zero status when the first argument is missing, replacing a four-line if-statement with one line.
How do you set a default value for a shell variable with the colon?#
: "${DOTFILES_PATH:=$HOME/.dotfiles}" sets the variable to a default if it is unset or empty, without triggering any other side effect.
What does while : mean in a shell script?#
while :; do ... done is the idiomatic way to write an infinite loop that runs until it is broken from within. It shows up often in init scripts and entrypoints.
Continue Reading#
- Good Tools Are Invisible: Why Your Favorite Editor Might Be Holding You Back - The philosophy behind tools that disappear during use
- Terminal Agents Are the New Developer Runtime - How AI agents execute shell commands on your behalf
- Uniqlo's Bash Script Reverse Engineering - Real-world shell analysis in production
- Best CLI Tools for AI Development 2026 - The CLI landscape every developer should know
- Git Ignore: Methods Beyond .gitignore - Shell-level workflow tips for everyday dev
Sources#
- "A shell colon does nothing. Use it anyway" by Filip Roseen - refp.se/articles/your-shell-and-the-magic-colon
- Hacker News discussion (325 points, 137 comments) - news.ycombinator.com/item?id=49047453
Get the next deep dive like this in your inbox
One email a week on News and the rest of the AI dev stack. Free.
Read next on AI coding tools
Gleam Moves to Tangled: What the ATProto Code Forge Means for Developers
Gleam moved to Tangled, an ATProto-based code forge. What Tangled offers, what HN said about it, and what you gain or lose by leaving GitHub.
6 min readGood Tools Are Invisible: Why Your Favorite Editor Might Be Holding You Back
Ginger Bill argues that the best tools disappear during use - and that celebrating workarounds is a sign your tool has failed you.
5 min readOuter Shell: A Graphical Desktop for Your Remote Server via SSH
Outer Shell proposes a graphical desktop for remote servers over SSH, with apps served on Unix domain sockets. How it works, the HN debate and who it is for.
8 min readNew here? Start with
Technical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.





