Concept Flow - Custom exit codes (exit N)
Start Script
Run commands
Call exit N
Script stops
Return exit code N to OS
The script runs commands, then stops immediately when exit N is called, returning N as the exit code to the operating system.
echo "Hello" exit 3 echo "Bye"
| Step | Command | Action | Output | Exit Code | Next Step |
|---|---|---|---|---|---|
| 1 | echo "Hello" | Print message | Hello | 0 | Continue |
| 2 | exit 3 | Exit script with code 3 | 3 | Stop | |
| 3 | echo "Bye" | Skipped because script exited | No |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| Exit Code | N/A | 0 | 3 | 3 |
Use 'exit N' in bash to stop a script and return a custom exit code N. Exit code 0 means success; non-zero means error or special status. Commands after 'exit' do not run. Useful for signaling script result to other programs or scripts.