true and false commands
Commands that do nothing except succeed (true, or :) or fail (false).
In more detail
They are useful where the shell needs a command, such as while true for an endless loop. cmd || true ignores a failure on purpose under set -e.
Example
grep -q dragon poem.txt || trueRelated terms
- exit code — A number a process returns when it finishes: 0 means success, anything else means something went wrong.
- set -e — The shell option that makes a script exit as soon as a command fails, instead of carrying on.
- OR list — Two commands joined by ||, where the second runs only if the first fails.
Taught in
- Redirection: Truncate, Append, Both Streams — Bash Scripting & Command Line Automation
- Exit Codes, And What Success Means — Bash Scripting & Command Line Automation
- set -e, set -u And pipefail: Promises And Traps — Bash Scripting & Command Line Automation