Quantcast
Channel: User Offirmo - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 7

What is the syntax of a complex condition in shell?

$
0
0

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 ?


Viewing all articles
Browse latest Browse all 7

Latest Images

Trending Articles





Latest Images