Regarding syntax, this is a simple methodology that I use (by example) to consistently and sanely manage Boolean logic:
# testsTests
var=
var=''
var=""
var=0
var=1
var="abc"
var=abc
if [[ -n "${var}" ]] ; then
echo 'true'
fi
if [[ -z "${var}" ]] ; then
echo 'false'
fi
# resultsResults
# var= # false
# var='' # false
# var="" # false
# var=0 # true
# var=1 # true
# var="abc" # true
# var=abc # true
If the variable is never declared the answer is: # false
So, a simple way to set a variable to true (using this syntax methodology) would be, var=1
; conversely, var=''
.
Reference:
-n
= True if the length of var string is non-zero.
-z
= True if the length of var string is zero.