TOPIC LINUX
Exit Codes how scripts know something failed
IN 10 SECONDS
Processes return an exit status code (0 to 255) to the parent shell. An exit code of 0 means success; anything else indicates an error.
GOTCHA Script exit codes default to the exit code of the last command executed inside the script, unless you write an explicit 'exit' call.
HOW EXIT CODES ACCUMULATE
01 Process exit application exits calling return or exit(1).
02 Parent trap kernel registers the exit code value in the process table.
03 Query the shell captures the return value in the special variable $?.
04 Chain check operators like && or || check this code to decide whether to trigger subsequent jobs.
POKE IT YOURSELF
echo $? — print the exit status code of the last executed command
false || echo \"failed\" — test exit code logic chaining
Drill this topic →
~60 sec read