The ; is straight forward, it always executes command2.
But how do you remember the rules for && and ||?
We have two commands separated by && or ||, which is OP.
command1 OP command2
These commands joined by the OP form a single big expression, which can either be good or bad.
We want to find out if the final expression is good or bad in as few steps as possible.
&& means AND.
good AND good == good
good AND bad == bad
bad AND anything == bad
We are executing the second command only if the first one is good.
command1 && command2
If command1 is good, we then also need to execute command2 to check if that one is good or bad, to determine the final state of the whole expression, which may be either good or bad.
If command1 is bad, bad AND anything is still bad, so we already know that the whole expression is bad, regardless of if command2 is good or not. so we do not need to run command2.
|| means OR
good OR anything == good
bad OR good == good
bad OR bad == bad
We are executing the second command if the first one is bad.
command1 || command2
If command1 is good, we automatically know that the final big expression is good, so we do not bother to run expression2.
If command1 is bad, then command2 may be either good or bad, so we need to run command2 to find out the end result of the whole big final expression.
For more informations see:
https://en.wikipedia.org/wiki/Boolean_algebra
Edited by BlueGalaxy, 31 May 2018 - 05:08 PM.