bash 设置生成的变量
我有一个变量名,由字符串 orig_endpoints_ 和文件名(无扩展名)组成。 我可以使用 eval echo 来查看此内容,如下所示:
[bash]# PCAP_FILE=test_w_three.pcap
[bash]# orig_endpoints_test_w_three=blah
[bash]# eval echo "\$$(echo orig_endpoints_${PCAP_FILE%.*})"
blah
[bash]#
现在如何将此变量设置为空格分隔的 src ips:dst ips 列表?我尝试了 eval set ,但似乎没有任何运气。
[bash]# orig_endpoints_test_w_three=
[bash]# tmpOrig="10.21.20.66:10.21.20.57 10.21.20.66:10.21.22.25 10.21.20.66:10.21.22.51 10.21.20.66:10.65.111.219 10.21.20.66:10.65.111.220 10.21.20.66:10.65.111.30 10.21.20.66:10.65.52.48"
[bash]# eval set orig_endpoints_${PCAP_FILE%.*}=$tmpOrig
[bash]# eval echo \$$(echo orig_endpoints_${PCAP_FILE%.*})
[bash]# echo $orig_endpoints_test_w_three
[bash]#
有人知道我该如何设置吗?
I have a variable name that is made up of the string orig_endpoints_ with the name of a file (sans extension).
I can view this using eval echo like so:
[bash]# PCAP_FILE=test_w_three.pcap
[bash]# orig_endpoints_test_w_three=blah
[bash]# eval echo "\$(echo orig_endpoints_${PCAP_FILE%.*})"
blah
[bash]#
Now how do I set this variable to a space separated list of src ips:dst ips? I tried eval set and don't seem to be having any luck.
[bash]# orig_endpoints_test_w_three=
[bash]# tmpOrig="10.21.20.66:10.21.20.57 10.21.20.66:10.21.22.25 10.21.20.66:10.21.22.51 10.21.20.66:10.65.111.219 10.21.20.66:10.65.111.220 10.21.20.66:10.65.111.30 10.21.20.66:10.65.52.48"
[bash]# eval set orig_endpoints_${PCAP_FILE%.*}=$tmpOrig
[bash]# eval echo \$(echo orig_endpoints_${PCAP_FILE%.*})
[bash]# echo $orig_endpoints_test_w_three
[bash]#
Would anybody know how I can set this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
引用很重要,这里不需要
set
AFAICT。Try:
Quoting is important, the
set
is unnecessary here AFAICT.尝试使用
声明
:Try with
declare
: