Skip to content

Instantly share code, notes, and snippets.

@svaj
Created August 7, 2018 16:15
Show Gist options
  • Save svaj/41dfc29d78e0c9c998640fae01fed475 to your computer and use it in GitHub Desktop.
Save svaj/41dfc29d78e0c9c998640fae01fed475 to your computer and use it in GitHub Desktop.
Bash fun to setup variables from a prefixed environment variables
#! /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