Using quotes with "${parameter:-word}" Parameter Expansion
If you are using the latest version of bash
(4.2 as of this writing), you can use the -v
option to test if a variable is set without trying to expand it at all.
if [[ -v FOO ]]; then echo "FOO=$FOO"else echo "FOO not set"fi
If you are using an older version, I would just use
if [[ -z ${FOO:-} ]];
The quotes aren't necessary, and IMO this looks cleanest.