true
Return a zero exit status (always true)
TLDR
Return a successful exit code
SYNOPSIS
true
DESCRIPTION
The true command is a very simple utility in Linux (and other Unix-like systems) whose sole purpose is to return a zero exit status (also known as an exit code of 0).
This is typically interpreted as a successful completion or a true condition. It doesn't print any output to the standard output or standard error. Its main usage is within shell scripts, primarily in conditional statements or loops where you need a command that will always evaluate to true or succeed.
It can be useful as a placeholder, or to satisfy syntax requirements in conditional tests without actually performing any real action. It effectively becomes a no-op (no operation) in the script.
true command is built-in shell command in many popular shells like bash, zsh, ksh, and others.
CAVEATS
Because the true command is so basic, it is rarely misused. However, confusing it with a command that *does* perform an action could lead to unexpected behavior in scripts. Its behavior is very different from conditional evaluation in programming languages.
USAGE EXAMPLE
The most common usage is within a shell script.
For example:
while true; do
echo "This loop will run forever."
sleep 1
done
or: if true; then
echo "This condition will always be met."
fi
EXIT STATUS
The true command always returns an exit status of 0.
HISTORY
The true command has existed since the earliest versions of Unix.
Its function has remained consistent: to return a successful exit status. The command exists to provide the same basic functionalities across different systems.