4 ms·
I'd advise against that kind of shortening. If you use set -e, which you should, then if [ a = b ]; then echo "Oops!" fi will do exactly what yo
by cesnja 3y ago
I'd advise against that kind of shortening. If you use set -e, which you should, then
if [ a = b ]; then
echo "Oops!"
fi
will do exactly what you imagined, but
[ a = b ] && echo "Oops!"
will quit with an error if expression a does not equal expression b.
- Calzifer 3y agoNo it won't. set -e is implicit disabled for the first command with && and ||. Same for a command after if/while/until and after !. It should only matter if you implicit return immediately after. $ bash -ec 'if [ 1 = 2 ]; then echo true; fi; echo $?' 0 $ bash -ec '[ 1 = 2 ] && echo true; echo $?' 1 In both cases it does not quite and execute the last echo.