Hi,
I trying to test two condition together (AND) under bash but it’s not working…
The goal is ti have True when two variables are either not set or empty (empty string)
I’ve tried
if [[ -n VARIABLE1 && -n VARIABLE2 ]]; then
echo "OK"
fi
Here I get the “OK” no matter what .
Thanks.
You’re probably wanting
[ -z "${VAR1}" -a -z "${VAR2}" ]
. Note in bash that there are minor differences in how[ ]
and[[ ]]
tests are handled. You can pull up a handy cheat sheet of the operands on most distros by runningman test
, though you’ll need to read through the CONDITIONAL EXPRESSIONS section ofman bash
if you want to see the minor differences of the single vs double square bracket commands (mostly whether locale applies to string order, as well as whether operands are evaluated in numeric comparisons).