Skip to content

true Command Cheat Sheet

true does nothing, successfully. It always returns an exit status of 0.


Synopsis

true

Usage

Infinite Loop

A clearer way to write infinite loops than while :.

while true; do
    echo "Running..."
    sleep 1
done

Placeholder for If Statements

If you are sketching out logic but haven't written the code yet.

if [ -f config.txt ]; then
    true # Do nothing for now
else
    echo "Config missing"
fi

Overwriting Exit Status

Force a success status after a failing command.

command_that_might_fail || true
# The script continues even if command failed (if using set -e)

  • false: Does nothing, unsuccessfully (exit status 1).
  • : (Colon): Shell builtin that is equivalent to true.