bash scripting – how do you take a result of a command and use it?

You almost certainly should not check the error message. Instead just do:

cmd || exit

If cmd fails and writes the message “AZERTY already exists, please check the error” to stderr, then that message will appear and the script will exit with whatever non-zero value cmd exited with. Some commands return non-zero values that have meaning, and you may want to suppress that (for consistent return values from your script) or change that with something like:

cmd || exit 1

On the other hand, if cmd is poorly written and returns a zero value when it “fails” (I’m putting that in quotes since a reasonable definition of “fail” is “return non-zero”), then that is a bug in cmd which should be fixed.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top