1

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
  • 345
  • 3
  • 17

1 Answers1

3

You probably want to do something like:

bail() {
   echo "$*"
   exit 1
}
command_that_could_fail || bail "command failed"
DopeGhoti
  • 73,792
  • 8
  • 97
  • 133