Boolean (/Logical) Operators

&& Logical AND $(( a != b ))
|| Logical OR $(( a > b ))
! Negation (inversion) $(( a >= b ))

 

  • The right side of && will only be executed if the EXIT STATUS of the left is zero (i.e. no errors).
  • || is the opposite and will only evaluate the right side if the left side exit status is nonzero.
  • If the EXIT STATUS evaluates to TRUE, it returns a zero. If FALSE it returns a nonzero.
#!/bin/bash
a=TRUE; echo 'a =' $a
b=FALSE; echo 'b =' $b

if [[ $a == TRUE ]] && [[ $b == TRUE ]]
	then
		echo "Both a AND b are TRUE"
	else
		echo "Both are AND b are not TRUE"
fi

if [[ $a == FALSE ]] || [[ $b == TRUE ]]
	then
		echo "Either a OR b are TRUE"
	else
		echo "Either a OR b are not TRUE"
fi

if [[ ! $a = FALSE ]]
	then
		echo "a was not set false"
	else
		echo "a was set true"
fi

*remember, it is the result of the EXIT STATUS that is being evaluated