Created
March 1, 2023 13:34
-
-
Save gmolveau/f8b370b17a6386fb632b8b0f7821f8af to your computer and use it in GitHub Desktop.
bash check that a list of environment variables is set
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
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