-
-
Save terenced/7ca3871d6e73e8b5199b5dc341e1c430 to your computer and use it in GitHub Desktop.
How to check if a variable is set in bash
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
+----------------------+------------+-----------------------+-----------------------+ | |
| if VARIABLE is: | set | empty | unset | | |
+----------------------+------------+-----------------------+-----------------------+ | |
- | ${VARIABLE-default} | $VARIABLE | "" | "default" | | |
= | ${VARIABLE=default} | $VARIABLE | "" | $(VARIABLE="default") | | |
? | ${VARIABLE?default} | $VARIABLE | "" | exit 127 | | |
+ | ${VARIABLE+default} | "default" | "default" | "" | | |
+----------------------+------------+-----------------------+-----------------------+ | |
:- | ${VARIABLE:-default} | $VARIABLE | "default" | "default" | | |
:= | ${VARIABLE:=default} | $VARIABLE | $(VARIABLE="default") | $(VARIABLE="default") | | |
:? | ${VARIABLE:?default} | $VARIABLE | exit 127 | exit 127 | | |
:+ | ${VARIABLE:+default} | "default" | "" | "" | | |
+----------------------+------------+-----------------------+-----------------------| | |
https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment