Created
January 25, 2016 09:47
-
-
Save hidekuro/7db8891e7174009b78bc to your computer and use it in GitHub Desktop.
複数の変数名の変数値存在チェックを行うBashスクリプト断片
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
#!/bin/bash | |
# required variables | |
required_vars=("FOO" "BAR" "BAZ") | |
# check defined | |
for VAR_NAME in "${required_vars[@]}"; do | |
eval var_temp='$'$VAR_NAME | |
if [[ -z "$var_temp" ]]; then | |
echo "$VAR_NAME is undefined." 1>&2 | |
usage_exit | |
fi | |
unset var_temp | |
done | |
unset required_vars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment