Skip to content

Instantly share code, notes, and snippets.

@hidekuro
Created January 25, 2016 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidekuro/7db8891e7174009b78bc to your computer and use it in GitHub Desktop.
Save hidekuro/7db8891e7174009b78bc to your computer and use it in GitHub Desktop.
複数の変数名の変数値存在チェックを行うBashスクリプト断片
#!/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