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

Return/exit values outside 0-255 are undefined in POSIX sh.

Problematic code:

#!/bin/sh
echo "Process failed" >&2
exit -1

Correct code:

#!/bin/sh
echo "Process failed" >&2
exit 1

Rationale:

You have declared your script as compatible with POSIX sh (#!/bin/sh), but appear to use return or exit with a value outside the range 0-255.

This is undefined behavior, and may work, wrap, or fail, depending on the implementation.

Avoid implementation specific behavior by only using return and exit codes in the range 0-255.

Exceptions:

None.

Related resources:

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

Clone this wiki locally