Bash: How to evaluate env variable stored in string varable?

809 views Asked by At

I parsed a string from a docker-compose.yml, stored it in a variable but now I want to resolve it.

Example:

export TAG=latest
export image_name_and_tag=some_image_name:$TAG

How can I echo $image_name_and_tag?

The answer should be "some_image_name:latest"

tried already:

echo ${image_name_and_tag#*:}        # To echo the tag
echo '${image_name_and_tag}' | envsubst
eval "echo $image_name_and_tag"

and many more. The problem is with "$" inside the string. Without it, I got it to work.

0

There are 0 answers