Resolve bash variable containted in another variable

Posted by kogut on Stack Overflow See other posts from Stack Overflow or by kogut
Published on 2010-05-18T07:29:21Z Indexed on 2010/05/18 9:30 UTC
Read the original article Hit count: 220

Filed under:
|
|

I have code like that:

TEXT_TO_FILTER='I would like to replace this $var to proper value'
var=variable

All I want to get is:

TEXT_AFTER_FILTERED="I'd like to replace this variable to proper value"

So I did:

TEXT_AFTER_FILTERED=`eval echo $TEXT_TO_FILTER`
TEXT_AFTER_FILTERED=`eval echo $(eval echo $TEXT_TO_FILTER)`

Or even more weirder things, but without any effects. I remember that someday I had similar problem and I did something like that:

cat << EOF > tmp.sh
echo $TEXT_TO_FILTER
EOF
chmod +x tmp.sh
TEXT_AFTER_FILTERED=`. tmp.sh`

But this solution seems to be to much complex. Have any of You heard about easier solution?

© Stack Overflow or respective owner

Related posts about bash

Related posts about string