Last active
June 4, 2019 13:08
-
-
Save empeje/257128cb16ffa17211cde7d6c7bd8a65 to your computer and use it in GitHub Desktop.
Fallback Environment Variable 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
#!/usr/bin/env bash | |
fallback_env() { | |
local TARGET_VARIABLE="$1" | |
local FALLBACK_VALUE="$2" | |
local CURRENT_VALUE=$(env | grep "^${TARGET_VARIABLE}=" | awk -F '=' '{print $2}') | |
if [[ -z "$CURRENT_VALUE" ]]; then | |
build_message "${TARGET_VARIABLE} is not set and will defaulting to ${FALLBACK_VALUE}" | |
eval "export ${TARGET_VARIABLE}=${FALLBACK_VALUE}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment