Addendum - It is a relevant aside that you can put multiple statements in each block of a properly formatted if/then/elif/else without much special effort (though it does take some finagling on the if
part) but the ternary construct requires that you create blocks yourself.
if true && false || oops
then : "this shan't be executed"
: but I can put several statements anyway
elif true && true || oops
then echo hello
echo more statements!
else : I could put more statements here too
: see?
fi
bash: oops: command not found
hello
more statements!
To create multiple-statements blocks in a ternary you need something like this -
true && {
echo ok
echo more
oops!
} || false {
echo This still has the same logical vulnerability, now made *worse*
echo oh, woe.
}
ok
more
bash: oops!: command not found
echo This still has the same logical vulnerability
This still has the same logical vulnerability
echo oh, woe.
oh, woe.
}
bash: syntax error near unexpected token `}'
It could be cleaned up a bit, but that isn't the point.
They aren't the same.