Correct way for you would be:
if [[ $REG = 'true' && $VIN = 'true' ]]; then
echo "$REG $VIN"
fi
This is the most correct and safe way (unlike executing your $REG
and $VIN
as other answers suggest). For example, what is going to happen if $REG
variable is empty? Or what if it equals to something different than just true
or false
?
If you want boolean behavior in bash, then consider the fact that empty strings are falsy.
REG=1
if [[ $REG ]]; then
echo '$REG is true!'
fi
or like that for multiple variables:
REG=1
VIN=''
if [[ $REG && $VIN ]]; then
echo '$REG and $VIN are true!'
fi
if [[ $REG && ! $VIN ]]; then
echo '$REG is true and $VIN is false!'
fi
So, if you want something to be false
, then either leave it unset or use an empty string.