opscape

Shell builtins · bash builtin

true

Do nothing and exit with status 0 (success).

true

8 of 8 examples run in Debian 13.7 on 2026-10-31 · manual: true(1)

true does nothing, successfully: it exits with status 0 and prints nothing. That is useful wherever the shell wants a command but you have nothing to run: an endless while true loop, a placeholder in an if branch, or || true after a command whose failure you have decided to tolerate under set -e.

In bash it is a builtin, so it costs no process. There is also an executable, /usr/bin/true, used when no shell is involved (for example as a do-nothing command in a config file). The colon command : is the older built-in equivalent and behaves the same, except that : is a POSIX special builtin.

Its opposite is false.

Examples

Check its exit status

true; echo "exit: $?"
explain
output
exit: 0

Nothing is printed by true itself; $? shows the status 0.

Loop until something breaks out

n=0
while true; do
  n=$((n + 1))
  [ "$n" -ge 3 ] && break
done
echo "stopped after $n rounds"
output
stopped after 3 rounds

while true runs forever on its own; the break inside the loop is the real exit condition. Common for retry and polling loops.

Tolerate one failing command under set -e

set -e
rm old-cache.tmp 2>/dev/null || true
echo "still running"
output
still running

Without || true, the failed rm (there is no such file) would end the script immediately because of set -e. With it, the list as a whole succeeds.

See what happens without || true

set -e
rm old-cache.tmp 2>/dev/null
echo "never printed"
outputexit 1

(no output)

The script stops at the failing rm, with rm's status 1, and the echo never runs.

Use the colon builtin the same way

: ; echo "exit: $?"
while :; do echo "once"; break; done
output
exit: 0
once

: also does nothing and returns 0. You will see it in older scripts and in idioms such as : "${VAR:=default}", where its arguments are evaluated for their side effects.

Fill an empty branch

if grep -q ERROR logs/app.log; then
  true   # TODO: alert someone
else
  echo "no errors"
fi
echo "exit: $?"
output
exit: 0

Bash refuses an empty then branch with a syntax error, so a placeholder command is needed. grep found errors, so the branch ran true and the if statement's status is 0.

See the builtin and the program

type -a true
explain
output
true is a shell builtin
true is /usr/bin/true
true is /bin/true

type -a lists every form bash could run: the builtin first (which wins), then the executables in PATH. /bin is a link to /usr/bin on current Debian, so the program appears twice.

Know that the builtin ignores --help

true --help; echo "builtin exit: $?"
/usr/bin/true --version | head -1
output
builtin exit: 0
true (GNU coreutils) 9.7

The bash builtin ignores every argument. GNU /usr/bin/true is the exception to "true does nothing": it recognizes --help and --version when they are its only argument.

Common pitfalls

  • Sprinkling || true over a whole script to silence set -e. It also hides the failures you care about; apply it only to commands whose failure is genuinely acceptable, or test the status explicitly.

  • Writing while [ true ] or if [ false ]. That tests whether the string true or false is non-empty, which is always the case, so [ false ] succeeds. Call the command: while true.

GNU vs BSD and macOS

The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).

  • Every shell has true as a builtin, and every system has /usr/bin/true or /bin/true. Only GNU's executable responds to --help/--version.

Options worth knowing

A selection, described in our own words. For the full list, see true(1).

OptionWhat it does
--helpGNU /usr/bin/true only: print usage and exit.
--versionGNU /usr/bin/true only: print the version and exit.

Related