Session and utilities
The true command
Does nothing and exits with code 0, the success code. Useful in scripts and loops.
Most useful options
--helpPrints the help of /usr/bin/true. The bash builtin does not print it: it shows nothing--versionPrints the version of /usr/bin/true. The bash builtin does not show itCopy-ready examples
$ true && echo okexits successfully, so the right side of && runs.Example output
ok
$ true; echo $?shows the exit code of the last command: 0.Example output
0
$ printf 'a\nb\n' | { while true; do read -r l || break; echo "eco $l"; done; }loop that keeps going while true says so; read ends the loop when the input runs out.Example output
eco a eco b
$ /usr/bin/true --help | head -n 1the help of the external program, which the builtin does not offer.Example output
Usage: /usr/bin/true [ignored command line arguments]
You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| bash: nodir/x: No such file or directory | The redirection fails before true runs, because the folder nodir does not exist. The exit code is 1, not 0. | Create the folder with mkdir nodir or fix the path before redirecting. |
| bash: tru: command not found | The name is misspelled, so the shell finds no command and returns 127. | Write true in full and in lowercase. type true shows how the shell resolves it. |
Typical mistakes
- As a builtin, true --help prints nothing. For the help, use /usr/bin/true --help or help true.
- while true without break or exit is an infinite loop. Stop it with Ctrl+C or add an exit condition.
- true does not look at the previous command: its 0 only says that true itself finished successfully.
Differences from similar commands
/usr/bin/true: is the standalone program. It accepts --help and --version; the bash builtin does not.:: is another builtin that also exits with 0 without doing anything. It is used the same way in loops, as while :.- test: evaluates conditions on files or strings. true evaluates nothing and always exits with 0.
FAQ
What is true used for in a script?
For loops that run until you decide to stop, such as while true, or to give a fixed success result in a condition.
What is the difference from /usr/bin/true?
A bare true is run by bash, with no separate process. /usr/bin/true is the program, and it is the one that responds to --help and --version.
What exit code does it always return?
Zero. Check it with true; echo $? and you will see 0.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course