Bash:如何评估存储在字符串变量中的环境变量?
我从 docker-compose.yml 解析了一个字符串,将其存储在一个变量中,但现在我想解析它。
示例:
export TAG=latest
export image_name_and_tag=some_image_name:$TAG
如何回显 $image_name_and_tag?
答案应该是“some_image_name:latest”,
已经尝试过:
echo ${image_name_and_tag#*:} # To echo the tag
echo '${image_name_and_tag}' | envsubst
eval "echo $image_name_and_tag"
还有更多。问题出在字符串内的“$”。没有它,我就能让它工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论