If want to express the following test in shell (sh) :
if ( a == 1 && ( b == 1 || b == 2 )) { ... }
So far, the best I have been able to write is this :
if [[ $a -eq 1 ]]; then
if [[ $b -eq 1 || $b -eq 2 ]]; then
...
fi
fi
I don't know how to compound && and || with correct precedence. Googling has not given me any answer (tutorials only give basic examples, if any)
What is the syntax to combine those two if into one ?
ksh
? Then your initial code would require only one more pair of parenthesis:if (( a == 1 && ( b == 1 || b == 2 ))); then :; fi
– manatwork Jan 10 '12 at 17:18