Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Created March 1, 2023 13:34
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 gmolveau/f8b370b17a6386fb632b8b0f7821f8af to your computer and use it in GitHub Desktop.
Save gmolveau/f8b370b17a6386fb632b8b0f7821f8af to your computer and use it in GitHub Desktop.
bash check that a list of environment variables is set
missing=0
ENV_VARS=(
DB_USER
DB_NAME
DUMP_FILE
)
for env_var in "${ENV_VARS[@]}"; do
if [ -z "${!env_var:-}" ]; then
echo "missing variable: ${env_var}"
missing=1
fi
done
[[ $missing -ne 0 ]] && exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment