Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operations on boolean variables

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
like image 330
pms Avatar asked Jun 09 '26 06:06

pms


1 Answers

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?

like image 71
pms Avatar answered Jun 11 '26 20:06

pms