Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Shell Builtins

The Bash : (colon) command

Reference for the Bash colon builtin: the null command that does nothing and succeeds, used for empty bodies, default assignments, and comment blocks.

The colon : is a builtin that does nothing and returns status 0. It is required by POSIX, so it works in every shell. What makes it more than a curiosity is that its arguments are still expanded before being thrown away. That side effect is what turns it into a tool: : ${VAR:=default} assigns a default without running any real command.

It is also the traditional placeholder where the grammar demands a command but you have nothing to run yet, such as an empty then branch or an endless loop condition.

Terminal
: ${LOG_DIR:=/var/log/app}
while :; do work; done

Try it

Bash Defaults through expansion side effects

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Placeholders, loops and comment blocks

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
: [ARGUMENTS...]
Name Description
ARGUMENTS Expanded as usual (variables, command substitution, arithmetic, ${var:=x}), then discarded.

Returns: always 0, unless an expansion fails (for example ${var:?} on an unset variable), in which case the shell reports the error and a non-interactive shell exits.

Edge cases: redirections on : still happen, so : > file creates or empties a file.

Usage notes

  • Defaults. : "${VAR:=value}" is the classic idiom for "set VAR to this if it has no value". Quote the expansion to avoid word splitting of the throwaway result.
  • Required values. : "${VAR:?message}" stops the script with message when VAR is unset or empty.
  • Space required. : is a command word, so :foo is a command named :foo. Write : foo.
  • Empty bodies. Functions, then branches and case arms may not be empty; : fills the gap. true works the same and reads more clearly to beginners.
  • Endless loops. while :; do ...; done is common in older scripts.
  • Block comments. : <<'EOF' ... EOF swallows many lines. Quote the delimiter or the text is still expanded, including $(...). Most editors make real # comments easier to maintain.
  • Truncating files. : > file is a portable way to empty a file without a subshell or cat.
  • Not the same as #. A comment is removed by the parser; : runs and expands its arguments, so side effects and errors inside it are real.
  • Debugging. With set -x, : label lines show up in the trace and can act as visible markers.