Created
December 12, 2022 17:57
-
-
Save dekobon/590038b65d16d4472636c8c24c6d4e05 to your computer and use it in GitHub Desktop.
Example of different bash string tests
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
#!/usr/bin/env bash | |
# a) | |
unset FOO | |
if [ ! -z ${FOO+x} ]; then | |
echo "a) is true" | |
fi | |
# b) | |
FOO="" | |
if [ ! -z ${FOO+x} ]; then | |
echo "b) is true" | |
fi | |
# c) | |
FOO="BAR" | |
if [ ! -z ${FOO+x} ]; then | |
echo "c) is true" | |
fi | |
echo "###" | |
# d) | |
unset FOO | |
if [ -n ${FOO+x} ]; then | |
echo "d) is true" | |
fi | |
# e) | |
FOO="" | |
if [ -n ${FOO+x} ]; then | |
echo "e) is true" | |
fi | |
# f) | |
FOO="BAR" | |
if [ -n ${FOO+x} ]; then | |
echo "f) is true" | |
fi | |
echo "###" | |
# g) | |
unset FOO | |
if [[ -v FOO ]]; then | |
echo "g) is true" | |
fi | |
# h) | |
FOO="" | |
if [[ -v FOO ]]; then | |
echo "h) is true" | |
fi | |
# i) | |
FOO="BAR" | |
if [[ -v FOO ]]; then | |
echo "i) is true" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment