Ensuring Distinguishable Exit Codes for Shell Scripts
1
vote
2
answers
77
views
Say I have two shell scripts,
a.sh
and b.sh
, where a.sh
calls b.sh
somewhere inside. Then, say that b.sh
could exit with exit codes 0
, 1
, or 2
.
What are some techniques that can be employed to ensure that the exit codes of a.sh
are distinguishable from the exit codes of b.sh
? For example, if we decide that a.sh
could exit with exit code 1
, then that is ambiguous to the caller -- did a.sh
fail, or did b.sh
fail ? So that means that a.sh
shouldn't use exit codes 1
or 2
. But there are only a limited number of exit codes to pick from, and b.sh
may theoretically add any number of additional exit codes as it evolves.
Are there techniques that can be employed to pass along some bit of extra data with an exit code to ensure that we, as script users, are able to differentiate between _which_ program actually failed ? Or as script authors, are we meant to assume that our scripts will be treated as a black box, and that our users aren't meant to have any insight into the individual operations that the script we're running is performing ? In other words is the exit code of a shell script meant to only ever be interpreted as the result of the outermost script ?
Asked by Pacopenguin
(113 rep)
Feb 13, 2024, 06:56 PM
Last activity: Feb 14, 2024, 11:37 AM
Last activity: Feb 14, 2024, 11:37 AM