Skip to content
Vidar Holen edited this page Nov 27, 2026 · 1 revision

Exit codes wrap to the range of 0-255. Prefer a canonical exit code.

Problematic code:

exit -1

Correct code:

exit 1

Rationale:

Exit codes are subject to the Unix Programming Model, and should be 0 (success) or 1-255 (failure). Values outside this range may wrap or fail.

Prefer using a value in range rather than relying on implementation specific behavior.

Exceptions:

None. Note in particular that -1 is a common error code in other languages like C, but non-canonical in shell scripts. The more canonical and appropriate "generic error" value is exit 1.

Related resources:

  • Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!

Clone this wiki locally