Created
March 31, 2019 21:18
-
-
Save StudioEtrange/80379a5cdca379fd527741693458ca6b to your computer and use it in GitHub Desktop.
bash var defined / undefined
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://stackoverflow.com/a/10965292 | |
[ -n "$var" ] && echo "var is set and not empty" | |
[ -z "$var" ] && echo "var is unset or empty" | |
[ "${var+x}" = "x" ] && echo "var is set" # may or may not be empty | |
[ -n "${var+x}" ] && echo "var is set" # may or may not be empty | |
[ -z "${var+x}" ] && echo "var is unset" | |
[ -z "${var-x}" ] && echo "var is set and empty" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment