Check if a variable is set
For newer versions of bash, you can use the -v flag:
[[ -v var ]]For older versions of bash, you can use the +x parameter expansion:
if [ -z ${var+x} ]; then echo "var is unset"; else echo "var is set to '$var'"; fiFor newer versions of bash, you can use the -v flag:
[[ -v var ]]For older versions of bash, you can use the +x parameter expansion:
if [ -z ${var+x} ]; then echo "var is unset"; else echo "var is set to '$var'"; fi