LINUX / A CONCEPT NOTE
Exit Codes
how scripts know something failed
Overview · mechanism
pitfall · examples
01 / THE SHORT VERSION
The idea in a few sentences.
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.
02 / FOLLOW THE MECHANISM
How exit codes accumulate
Process exit
application exits calling return or exit(1).
Parent trap
kernel registers the exit code value in the process table.
Query
the shell captures the return value in the special variable $?.
Chain check
operators like && or || check this code to decide whether to trigger subsequent jobs.
04 / COMMAND NOTES
Read the command, then the result.
Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.
print the exit status code of the last executed command
echo $?test exit code logic chaining
false || echo \"failed\"05 / CHECK YOURSELF
Could you explain Exit Codes to a teammate?
Try it out loud in two sentences: what it is, and the one detail that changes the picture. If you stall, the gap is the part to reread.
Up next in Linux & systemsShell Startup Chain.bashrc vs .profile