Note that
if command1; then
command2
else
command3
fi
is not equivalent to command1 && command2 || command3
.
- If
command1
fails,command2
is skipped andcommand3
runs, as expected. - If
command1
succeeds, andcommand2
runs and succeeds,command3
is skipped, as expected. - If
command1
succeeds, andcommand2
runs and fails,command3
is run, which differs from theif
statement.
You would need to use something like:
command1 && { command2; true; } || command3
which would force the right-hand operand to &&
to succeed, regardless of the success of command2
, so that command3
is never run when command1
succeeds.