true
Do nothing, successfully (exit with 0)
Overview
The `true` command does nothing except exit with a status code of 0, which indicates success. It is often used in shell scripts to create infinite loops or to provide a command that always succeeds.
Syntax
true [ignored_arguments]Common Options
[arguments]Any arguments provided are typically ignored.
--help(GNU version) Display help and exit.
--version(GNU version) Output version information and exit.
:In many shells (like Bash), the colon `:` is a built-in command synonymous with `true` and is often more efficient.
Examples
$ true
Exits with a status code of 0.
$ if true; then echo "Success!"; fi
The commands within the `if` block will always execute.
$ while true; do echo "Looping..."; sleep 1; break; done
Creates an infinite loop that executes once due to `break`.
$ : # This is a comment, and the line successfully does nothing
Using the colon built-in as a `true` equivalent.
Related Commands
truesuccessexit 0scriptingloopboolean