Use it when configuring, checking or troubleshooting Exit Codes in Scripting.
Exit Codes · Scripting
Exit Codes provide a compact process-level result contract to callers and schedulers. Reliable scripts map meaningful success and failure classes consistently while preserving detailed diagnostics elsewhere.
1. Exit 0 = success; non-zero = failure.
2. Define meaningful codes.
3. Propagate failures (set -e, pipefail).
4. Check native command codes in PowerShell.
5. Callers rely on them.
script → exit code → caller decision
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
operation result → classify terminal state → preserve first/required failure → map to exit code → caller/scheduler interpretation → correlated diagnostics
Healthy evidence: success and failure codes are documented, child failures propagate, partial failure cannot become zero and diagnostics correlate to the exit status.
Step 2 Failure modes and next checks Narrow the fault
Suspicious evidence: always-zero scripts, status overwritten by cleanup, inconsistent code meanings, non-zero ignored by callers or logs that disagree with the returned code.
Step 3 Common mistakes Narrow the fault
- Ignoring exit codes.
Step 4 Where it fails Narrow the fault
Where Exit Codes usually goes wrong: process exit-status contract, signal/termination distinction, pipeline propagation and semantic mapping.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Exit code 0 ≠ business outcome success; the script may not have verified the target or may define success too weakly.
- Non-zero exit ≠ root cause; it signals failure class, while logs/exception/command evidence explain why.
- Last command exit code ≠ whole script status; later commands can overwrite prior failure state.
- Printed error ≠ failed process; a script can emit an error message and still return zero unless explicitly handled.
echo $?— last exit code (Bash)$LASTEXITCODE— PowerShell native command exit- Documented exit codes — contract
ReferenceWhat it is1 section · depth on demand
Core model
Define which terminal conditions map to zero and non-zero codes, propagate child-process failures deliberately, avoid overwriting an earlier failure with later success and pair the code with structured context for diagnosis.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
An exit code shows only the process-level result according to the script's contract, but it does not show target state or identify root cause.
In depth
Exit codes are the number a program returns when it ends: 0 means success, anything else means failure. Schedulers, CI pipelines and other scripts rely on them to decide whether to continue, so scripts must return honest exit codes.
| Code | Common meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Misuse (bad arguments) in many tools |
| 126/127 | Not executable / command not found (shell) |
| 128+n | Killed by signal n (e.g. 137 = SIGKILL) |
set -euo pipefail
backup.sh || { echo "backup failed with $?" >&2; exit 1; }
& robocopy src dst /E; if ($LASTEXITCODE -ge 8) { exit 1 } # robocopy: <8 is success
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Scripting > Exit Codes. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.python.org/3/ · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Exit Codes scripting boundary map
Fast input, runtime, execution, result and verification boundaries for Exit Codes.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Input / runtime | Effective inputs, runtime, working context and dependency versions are explicit | Hidden defaults, stale environment, wrong interpreter/path or unvalidated input |
| Logic / execution | Branch/function/module decisions and external actions expose per-operation results | Swallowed failures, shell reinterpretation, blind retries or last-result-wins behavior |
| Result / proof | Exit/exception/log evidence is correlated with independent target read-back | Process success or printed output treated as target success |
| Recovery / troubleshooting | First failed boundary is preserved, changed minimally and retested | Random edits, catch-all suppression or evidence destroyed before diagnosis |
Deep reference
Healthy vs suspicious evidence
Output interpretation
For Exit Codes, rely on structured fields and stable IDs (process exit-status contract, signal/termination distinction, pipeline propagation and semantic mapping) rather than text formatted for display.