resolve or flatten bash vars in string

This is the string

FE_DOMAIN=${HOST_PREFIX}pl8it.com

If I wanted to resolve this and output the result, you would think this would work

if [[ $line =~ (((.*)_DOMAIN)=(.*)) ]];then
                result=`eval "export FE_DOMAIN=${HOST_PREFIX}" && echo \$${BASH_REMATCH[2]}`
                echo "$result"

this is what I get

9315{BASH_REMATCH[2]}

so instead I used printenv

if [[ $line =~ (((.*)_DOMAIN)=(.*)) ]];then
                result=`eval "export $line" && printenv ${BASH_REMATCH[2]}`
                echo "$result"

printenv requires that you pass it the env without the “$”

printenv ADMIN_EMAIL_DEFAULT

Leave a Reply

Your email address will not be published.