[SOLVED] bash - if command fails, get return code despite set -e
by vincix from LinuxQuestions.org on (#536WM)
I've seen in many places that that the best practice in bash is to start with something to the effect of:
Code:set -euo pipelineSo that you have better control over the code.
I was wondering what the best practice is if I wanted to catch the return code of a failing command, while setting set -e.
A sort of example:
Code:set -euo pipeline
some_command || EXIT_CODE=${?}
[...]
if [[ EXIT_CODE -ne 0 ]]
echo "Script failed."
fiIs there a better way of doing that? Does that look ok? How would one 'normally' go about doing that?


Code:set -euo pipelineSo that you have better control over the code.
I was wondering what the best practice is if I wanted to catch the return code of a failing command, while setting set -e.
A sort of example:
Code:set -euo pipeline
some_command || EXIT_CODE=${?}
[...]
if [[ EXIT_CODE -ne 0 ]]
echo "Script failed."
fiIs there a better way of doing that? Does that look ok? How would one 'normally' go about doing that?