In shell (especially POSIX shells like sh, bash, dash, zsh), : is a builtin command called the null command.
What it does
-
Does nothing
-
Always succeeds (returns exit status
0)
Why it’s useful
Even though it does nothing, : is surprisingly handy.
1. Placeholder in scripts
When syntax requires a command but you don’t want to do anything yet:
2. Infinite loops
Common idiom:
(: always succeeds, so the loop never ends.)
3. Default action in conditionals
When you want to explicitly do nothing:
4. Variable expansion with side effects
Often used to safely trigger parameter expansion:
-
Sets
VARtodefaultif it’s unset or empty -
No output, no side effects besides assignment
5. Redirecting without running a command
Since : does nothing, it’s useful with redirections:
6. Alternative to true
: is faster and more portable than calling /bin/true:
Summary
| Feature | : |
|---|---|
| Type | Shell builtin |
| Effect | Does nothing |
| Exit status | Always 0 |
| Common uses | Loops, placeholders, parameter expansion, redirection |

浙公网安备 33010602011771号