3

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?

joshlf
  • 365

1 Answers1

4

You probably want to do something like:

bail() {
   echo "$*"
   exit 1
}
command_that_could_fail || bail "command failed"
DopeGhoti
  • 76,081