Created
August 7, 2018 16:15
-
-
Save svaj/41dfc29d78e0c9c998640fae01fed475 to your computer and use it in GitHub Desktop.
Bash fun to setup variables from a prefixed environment variables
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 | |
set -e | |
# Below will find env vars prefixed with ${CI_ENVIRONMENT} and set env vars without the prefix to the prefixed value | |
# e.g. if ${development_CTP_CLIENT_SECRET} is defined, define $CTP_CLIENT_SECRET with the value from ${development_CTP_CLIENT_SECRET} | |
while read -r line | |
do | |
non_prefixed=${line#"${CI_ENVIRONMENT}_"} | |
declare -x $non_prefixed=${!line} | |
done < <(compgen -A variable | grep "${CI_ENVIRONMENT}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment