LinuxCommandLibrary

colon

Do nothing; it's a shell built-in

TLDR

Return a successful exit code

$ :
copy

Make a command always exit with 0
$ [command] || :
copy

SYNOPSIS

: [arguments …]

PARAMETERS

arguments
    Optional positional arguments; expanded (e.g., variables, substitutions) for side effects but ignored and not executed.

DESCRIPTION

The colon (:) is a POSIX-compliant shell built-in command found in shells like bash, dash, and zsh. It performs absolutely no action and always returns an exit status of 0, functioning as a reliable no-op (no operation).

Key uses include:
Placeholders in scripts where a command is required syntactically but no action is needed.
Infinite loops: while :; do ...; done or for :; do ...; done.
Side-effect evaluations: Arguments are expanded (e.g., parameter expansion, command substitution) but discarded, like : ${VAR:=default} to set defaults without output.
• Legacy comments: Before # was standard, : "comment" ignored lines.

Unlike true (which may be external), : is always a builtin, ensuring efficiency. Arguments are parsed for expansions but not executed, distinguishing it from eval. It's portable across Unix-like systems.

CAVEATS

Shell builtin only—no standalone binary. Slight shell variations in expansion; always succeeds (exit 0), unlike conditional commands.

EXAMPLES

: ${HOME:=/tmp} # Set HOME if unset
while :; do
echo 'Forever'
sleep 1
done
: $(/etc/hostname) # Expand but discard

HISTORY

Introduced in the Bourne shell (1977) by Stephen Bourne at Bell Labs. Standardized in POSIX.1-1988 and later revisions; evolved for scripting portability.

SEE ALSO

true(1), false(1), eval(1), test(1)

Copied to clipboard