4

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?

1
  • Just use braces instead of parentheses. Commented Aug 9, 2015 at 0:23

1 Answer 1

5

You probably want to do something like:

bail() {
   echo "$*"
   exit 1
}
command_that_could_fail || bail "command failed"
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.