I have a program which tests the error code of a script/command I provide. In some cases the command line returns a warning error code which i would like to ignore (exit with 0 instead of 5). I would like other error codes to pass the same, and for that to be a simple as possible (to keep that a single line command).
I've tried using pytest || [ $? -eq 5 ]
, which ignores error code 5 coming from command but will replace all non-zero error codes with 1 (instead of the actual error code).
I guess someone more experienced than me with bash could come up with a better solution faster than I.
Some more specific context:
I'm using pytest to test my projects. Some of them have no tests at the moment and pytest's default behavior is to treat that as an error (error code 5). I would like to treat that error as a success. Actually, I would like Travis to threat that error as success.
Thanks!
Using arithmetic expression:
exit $(( $? == 5 ? 0 : $? ))