引用名称包含点的bash变量 [英] Reference to a bash variable whose name contains dot

查看:95
本文介绍了引用名称包含点的bash变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash变量:agent1.ip,其值为192.168.100.137.当我在echo中像这样引用它时:

I have a bash variable: agent1.ip with 192.168.100.137 as its value. When I refer to it in echo like this:

echo $agent1.ip

结果是:

.ip

如何获取值?

更新:我的变量是:

推荐答案

Bash本身无法理解带点的变量名,但这并不意味着您的环境中不能包含此类变量.这是一个如何设置并将其全部集成的示例:

Bash itself doesn't understand variable names with dots in them, but that doesn't mean you can't have such a variable in your environment. Here's an example of how to set it and get it all in one:

env 'agent1.ip=192.168.100.137' bash -c 'env | grep ^agent1\\.ip= | cut -d= -f2-'

这篇关于引用名称包含点的bash变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆