I have a 3 part logic (A or B and C). Logically if A is true then true, or if B and C is true then true; But here is the error
-
if (A or B and C) -> should return true
if [ 1 -eq 1 ] || [ 2 -eq 2 ] && [ 3 -eq 30 ]; then echo "true"; else echo "false"; fi
returns false (should be true because “and C” is false at the end of the expression, is this a bug? or am I missing something?)
-
if (B and C or A) -> does return true
if [ 2 -eq 2 ] && [ 3 -eq 30 ] || [ 1 -eq 1 ]; then echo "true"; else echo "false"; fi
returns true (as should be)
Edit 2-
So is the best way going forward is to use parentheis around all the AND logic?
if [ 1 -eq 1 ] || ( [ 2 -eq 2 ] && [ 3 -eq 30 ] ); then echo "true"; else echo "false"; fi