This question already has an answer here:

I have a script with the following code:

command_that_could_fail || (echo "command failed"; exit 1)

However, the exit seems to just be exiting from the sub-command formed by the second part of the line (in parentheses), not from the script itself. Any way that I can make it behave as desired, and exit from the outer script?

marked as duplicate by Michael Homer, heemayl, G-Man, Anthon, maxschlepzig Aug 9 '15 at 7:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Just use braces instead of parentheses. – jimmij Aug 9 '15 at 0:23

You probably want to do something like:

bail() {
   echo "$*"
   exit 1
command_that_could_fail || bail "command failed"
  • Pleased to have helped! – DopeGhoti Aug 9 '15 at 2:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.