How to do complex conditionals in bash? (mix of 'and' &&, 'or' || ...) How to do complex conditionals in bash? (mix of 'and' &&, 'or' || ...) bash bash

How to do complex conditionals in bash? (mix of 'and' &&, 'or' || ...)


You almost got it:

if [[ "$a" == "something" || ($n == 2 && "$b" == "something_else") ]]; then

In fact, the parentheses can be left out because of operator precedence, so it might also be written as

if [[ "$a" == "something" || $n == 2 && "$b" == "something_else" ]]; then


if [[ "$a" == "something" ]] || [[ $n == 2 && "$b" == "something_else" ]]; then  ...fi