You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Vidar Holen edited this page Nov 27, 2026
·
1 revision
Bash wraps return codes to the range 0-255. Prefer a canonical return code.
(or Busybox)
Problematic code:
fail() {
echo"Failed">&2return -1
}
Correct code:
fail() {
echo"Failed">&2return 1
}
Rationale:
Bash and Busybox restrict return codes to the range 0-255, but you are returning a value outside this range. Provide an error code within this range to
Note that return should only be used for error status, and not for numerical results. The correct way to return the result of a computation is to output it to stdout and capture it with a command expansion: