Only using 0 and 1, period, and not differentiating between the situations 1 and 2 is a bit too sloppy though.
Only using 0 and 1, period, and not differentiating between the situations 1 and 2 is a bit too sloppy though.
If I was to advise someone I'd tell o interpret and write programs using the following rule of thumb and not to worry too much:
0 = success / true
1 = failure (read stderr) / false
>1 = failure (read stderr & docs)
- 2 is "misuse of shell built-ins" for bash [1] - Python's argparse uses 2 [2]
I feel like we looked at more but can't remember which all they were
[0] https://github.com/clap-rs/clap/pull/1637#issuecomment-58103...
[1] https://tldp.org/LDP/abs/html/exitcodes.html
[2] https://github.com/python/cpython/blob/main/Lib/argparse.py#...
$ ruby -e 'raise StandardError.new "oops"'
Traceback (most recent call last):
-e:1:in `<main>': oops (StandardError)
$ echo $?
1
And so will this one: $ ruby -e 'invalid method call'
Traceback (most recent call last):
-e:1:in `<main>': undefined local variable or method `call' for main:Object (NameError)
Did you mean? caller
So, it's nice to distinguish between a possibly unexpected exceptional exit (1), and an "error case detected by the programmer", which is what I use exit (2) for.https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LS...
That way automated CI pipelines (or whatever) can switch on the return code if needed rather than try to parse stderr
0, OK
1, Error
2, Bad arguments
However I'm not surprised that requirements evolved and somebody needs more structured and informative exit codes.