I just discovered set -u in bash and it helped me find several previously unseen bugs. But I also have a scenario where I need to test if a variable is defined
set -u
Unfortunatly [[ -v variable ]] is not supported in older versions of bash (at least not in version 4.1.5 I have on Debian Squeeze)
[[ -v variable ]]
You could instead use a sub shell as in this :
if (true $variable)&>/dev/null; then variable="$(...)" fi