Created
December 30, 2011 01:19
-
-
Save mblair/1537072 to your computer and use it in GitHub Desktop.
arggggggggghhhhh
This file contains 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
#!/usr/bin/env bash | |
#You need Bash >= 4.2.0 for this. | |
bash --version | head -n1 | |
set -o errexit | |
set -o xtrace | |
unset my_var | |
if test -v "$my_var"; then | |
echo "my_var is set" | |
else | |
echo "my_var is not set" | |
fi | |
my_var= | |
if test -v "$my_var"; then | |
echo "my_var is set" | |
else | |
echo "my_var is not set" | |
fi | |
my_var="a string" | |
if test -v "$my_var"; then | |
echo "my_var is set" | |
else | |
echo "my_var is not set" | |
fi | |
unset my_var | |
echo ${my_var-default} | |
my_var="a string" | |
echo ${my_var-default} | |
if test -v "$my_var"; then | |
echo "my_var is set" | |
else | |
echo "my_var is not set" | |
fi | |
#Do not use parameter expansion! | |
if test -v my_var; then | |
echo "my_var is set" | |
else | |
echo "my_var is not set" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment