I have just had unexpected result from writing the alternative form of if/then/else blocks.
> #this is the behaviour I expect:
> if [[ 1 -eq 1 ]]; then echo "good"; false; else echo "bad"; fi
good
> #assuming no error in the first block these brackets behave okay as well:
> [[ 1 -eq 1 ]] && { echo "good"; } || { echo "bad"; }
good
> #this however allows the process to jump into the first AND second block
> [[ 1 -eq 1 ]] && { echo "good"; false; } || { echo "bad"; }
good
bad
Why does the curly brace method pass the process to the second block. I'm aware there's some statements that there must be a ;
before the end of the block, but if bash blocks behave badly on an error condition as a last statement these blocks seem "unsafe" to use.