bash replace variable name in string with variable value

前端 未结 2 1406
孤独总比滥情好
孤独总比滥情好 2021-01-29 02:13

This is kind of a weird one. I have the following string:

I have a variable called REDIRECT set to: https://working.${MYDOMAIN}/blah/blah.

I need to

相关标签:
2条回答
  • 2021-01-29 02:35

    Just execute in bash:

    eval REDIRECT=$REDIRECT
    
    0 讨论(0)
  • 2021-01-29 02:50

    You may use this bash substitution:

    echo "${REDIRECT/\${MYDOMAIN\}/$MYDOMAIN}"
    

    or else, if you have envsubst utility then use:

    export MYDOMAIN
    envsubst <<< "$REDIRECT"
    
    0 讨论(0)
提交回复
热议问题