exit builtin
The builtin that ends the shell or script immediately with a chosen exit status, 0 for success.
In more detail
exit 1 is a general failure and exit 2 conventionally means the command was used wrongly. Without a number, exit uses the status of the last command. Any EXIT trap still runs on the way out.
Example
echo "usage: report.sh FILE" >&2; exit 2Related terms
- exit code — A number a process returns when it finishes: 0 means success, anything else means something went wrong.
- return builtin — The builtin that ends a function and sets its exit status, a number from 0 to 255, not a text value.
- EXIT trap — A trap on the special name EXIT, whose handler runs whenever the shell exits: at the end, on exit, or when set -e stops it.
Taught in
- Which Shell Am I In, And Getting Bash Five — Bash Scripting & Command Line Automation
- What Bash Does To A Line Before It Runs It — Bash Scripting & Command Line Automation
- The Unquoted Variable: Splitting And Globbing — Bash Scripting & Command Line Automation
- Exit Codes, And What Success Means — Bash Scripting & Command Line Automation
- Arguments: Dollar One, Dollar At, shift — Bash Scripting & Command Line Automation
- Option Parsing With getopts — Bash Scripting & Command Line Automation
- set -e, set -u And pipefail: Promises And Traps — Bash Scripting & Command Line Automation
- Processes, Jobs And Signals — Bash Scripting & Command Line Automation