dotkb

    Check if a variable is set

    (updated: )

    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'"; fi
    

    Sources

    https://stackoverflow.com/a/13864829