Automation · Bash Automation
Exit Codes
Cheat sheet · https://pcornel.dk/topic.php?topic=5284
Answer
Exit codes are the number a command returns: 0 for success and 1–255 for failure, available in $?. Scripts should exit non-zero on errors so callers and schedulers detect failures.
Remember
- 0 is success; non-zero is failure.
- $? holds the last exit code.
- Exit non-zero on errors.
First checks
echo $?— last exit codeset -e— exit on errorexit 3— explicit code
Verify in this order
command → exit code → decision
Where it usually breaks
Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5284