开发者

bash setting generated variables

开发者 https://www.devze.com 2023-04-02 22:08 出处:网络
I have a variable name that is made up of the string orig_endpoints_ with the name of a file (sans extension).

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.6开发者_JAVA百科6: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?


Try:

eval orig_endpoints_${PCAP_FILE%.*}='$tmpOrig'

Quoting is important, the set is unnecessary here AFAICT.


Try with declare:

declare orig_endpoints_${PCAP_FILE%.*}=$tmpOrig
0

精彩评论

暂无评论...
验证码 换一张
取 消