Im having trouble using a dynamic varaible, or variable within a variable.
Basically, a CI server has a bunch of environment variables set on a repo. They are doing multiple deploys from one repo, and based on the branch name, we read in the correct env variable, and echo back out the variable values in a config file to be used by application code later.
The application code only reads in one set of generic values, regardless of environemnt, for example DB_USERNAME
So, something like this...
CI Server ENV Variables
DEV_DB_USERNAME
STG_DB_USERNAME
PRD_DB_USERNAME
DEV_LAB_DB_USERNAME
STG_LAB_DB_USERNAME
PRD_LAB_DB_USERNAME
The Branch name can then be one of deploy-dev, deploy-stg, deploy-prd, or lab-dev, lab-stg, lab-prd.
So I have a bash script where I'm setting the branch name and ENV Var for testing that looks like:
#!/usr/bin/env bash
export TRAVIS_BRANCH="deploy-dev"
export DEV_DB_USERNAME="goodguy"
IFS="-" read TR_BRANCH DB_ENV TRAVIS_BRANCH <<< "$TRAVIS_BRANCH"
DB_ENV_UC=`echo "$DB_ENV" |tr '[:lower:]' '[:upper:]'`
if [[ ${TR_BRANCH} == "deploy" ]]
then
DB_USERNAME=\$${DB_ENV_UC}_DB_USERNAME
else
DB_USERNAME=\$${DB_ENV_UC}_LAB_DB_USERNAME
fi
echo "username is $DEV_DB_USERNAME"
echo "username is $DB_USERNAME"
first echo returns string: goodguy
second echo returns string $DEV_DB_USERNAME
How can I get the value of goodguy returned for $DB_USERNAME?