Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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?

share|improve this question

marked as duplicate by Michael Homer, heemayl, G-Man, Anthon, maxschlepzig Aug 9 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 at 0:23

1 Answer 1

up vote 1 down vote accepted

You probably want to do something like:

bail() {
   echo "$*"
   exit 1
}
command_that_could_fail || bail "command failed"
share|improve this answer
    
That worked; thanks! –  synful Aug 9 at 0:27
    
Pleased to have helped! –  DopeGhoti Aug 9 at 2:24

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