Binary Operators
Last updated
Last updated
The &&
and ||
operators each take two operands (making them binary). We will refer to the operand appearing on the left of the operator as the lvalue and the operand on the right the rvalue.
The exit status of the lvalue command determines, depending on which operator you use, if the rvalue command is executed.
The &&
operator acts as a logical AND between two commands and the ||
operator acts as a logical OR.
Any command, group of commands, or sub-shell can be used as an operand. Below are some examples:
Lines 2-5 demonstrate a multi-line rvalue grouped by braces.
Line 6 demonstrates an lvalue grouped by braces.
Line 7 demonstrates that an assignment lvalue. The exit status of an assignment is that of the last command executed in the sub-shell (date +%Y
). If executing date +%Y
results in anything but success we would assign a default year of 1979.
lvalue exit status
Operator
rvalue command
zero (SUCCESS)
&&
Executed
zero
∣∣
Not executed
non-zero (FAILURE)
&&
Not Executed
non-zero
∣∣
Executed