Operations on boolean variables

bash, boolean, sh, shell

Solution

This does work:

if ! $var1 && $var2; then
   echo "do sth"
fi

Maybe somebody can explain why -a and -o operators don't work and &&, ||, ! do?

Problem

In this question it has been shown how to use neat boolean variables in bash. Is there a way of performing logic operations with such variables? E.g. how to get this: ``` var1=true var2=false # ...do something interesting... if ! $var1 -a $var2; then <--- doesn't work correctly echo "do sth" fi ```

Original source

Related problems