I need to test if certain environment variables are set before running my script. I'm using a technique from this answer:
if [ -z ${var1+x} ]
echo "var1 not set"
exit 1
fi
This works well for string variables, but there's a parameter which needs to be an array. It has to be set, but could be empty.
foo=("foo" "bar" "baz")
[ -z ${foo+x} ] # false
bar=()
[ -z ${bar+x} ] # true
[ -z ${baz+x} ] # also true
So, my question is how do I declare an empty array to make it distinct from unset variable. I'd also like to test if variable is array (whether empty or not) or non array (whether set or unset).