Skip to content

Instantly share code, notes, and snippets.

@StudioEtrange
Created March 31, 2019 21:18
Show Gist options
  • Save StudioEtrange/80379a5cdca379fd527741693458ca6b to your computer and use it in GitHub Desktop.
Save StudioEtrange/80379a5cdca379fd527741693458ca6b to your computer and use it in GitHub Desktop.
bash var defined / undefined
#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