This question already has an answer here:

I have the following command:

/path/to/script.sh && echo "done."; exit 0 || echo "error."; exit 1

What I want is to echo "done" and exit with 0 if script succeeds and echo "error" and exit with 1 if it doesn't, but it is not working this way, it misses priorities.

How to handle this?

=== edit. ===

using {} also not works as needed. commands like ./true.sh && { echo done.; ./error.sh; } || { echo err.; echo err1; } works wrong, as it outpust done and all errors after it. ps: true returns 0, error returns 1.

marked as duplicate by Jeff Schaller, GAD3R, Rui F Ribeiro, countermode, Anthon Feb 17 '17 at 14:24

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.

if /path/to/script.sh; then
    echo "done."
    exit 0
    echo "error."
    exit 1

Or, staying with a one-liner:

/path/to/script.sh && echo done. || { echo error. ; exit 1; }

Your edit tells that A && { B1 ; B2 ; } || { C1 ; C2 ; } notation doesn't work. assuming B2 returns 1, which isn't your what your initial post states (where's the exit 0? Have you tried adding one?).

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