Article 536WM [SOLVED] bash - if command fails, get return code despite set -e

[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?latest?d=yIl2AUoC8zA latest?i=qC2iiEGd-Iw:RiXNsb-SSGU:F7zBnMy latest?i=qC2iiEGd-Iw:RiXNsb-SSGU:V_sGLiP latest?d=qj6IDK7rITs latest?i=qC2iiEGd-Iw:RiXNsb-SSGU:gIN9vFwqC2iiEGd-Iw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments