Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Exit Codes · Error Handling

Direct answer

Exit codes in error handling tell the caller whether automation succeeded: 0 for success, non-zero for distinct failures. CI pipelines and schedulers rely on them to mark jobs as failed.

When to use this

Use this when callers must know whether automation succeeded.

First 30 seconds

1. Exit codes signal results to callers (CI, schedulers).

2. 0 success, non-zero failure; document specific codes.

3. Propagate failures (set -e, pipefail).

4. Check native commands.

5. Test.

Operational verification

run → exit code → caller decision

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
process exit and shell error handling
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformprocess exit and shell error handling · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when callers must know whether automation succeeded.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

The negative fixture should deliberately exercise risks such as ambiguous target identity, stale inputs, partial success, unsafe retry, permission drift and confusing tool completion with target-evidence of the actual state, choosing the cases most relevant to process exit status as a contract, reserved/application-specific codes, pipeline/wrapper propagation and keeping stderr/output interpretation separate.

Step 2 Common mistakes Narrow the fault
  • Scripts that always exit 0.
Evidence references

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.

observation · 1
Key points
  • 0 means success, non-zero means failure.
  • Use distinct codes for distinct failures.
  • CI and schedulers rely on exit codes.
Key checks
  • echo $? — Bash
  • $LASTEXITCODE — PowerShell native
  • Documented exit code meanings — contract
ReferenceImportant terms & boundaries1 section · depth on demand

In depth

An exit code is the number a program returns to whatever started it: 0 means success, anything else means failure. Schedulers, CI pipelines and other scripts rely on it to decide whether to continue, so a script that prints an error but exits 0 hides its failure from every system around it.

CodeCommon meaning
0Success
1General error
2Misuse / invalid arguments
126Command not executable
127Command not found
130Interrupted (Ctrl+C)
137Killed (SIGKILL, often out of memory)
my_script.sh; echo "exit=$?"
set -o pipefail   # a pipeline fails if any command in it fails
$LASTEXITCODE        # native commands
exit 2               # return a specific code

Document the codes your own scripts return, especially when different failures need different handling.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docprocess exit and shell error handling current

Authoritative/upstream documentation reviewed for bounded claims in Error Handling > Exit Codes. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.gnu.org/software/bash/manual/bash.html · confidence 94%
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For process exit status as a contract, reserved/application-specific codes, pipeline/wrapper propagation and keeping stderr/output interpretation separate, prefer typed fields and stable IDs over human presentation text.

Confirmation

Confirm action

Continue?