我正在尝试用bash创建类似于字典的内容。
我的意思是类似于data = {"hostname1": <ip_address1>, "hostname2": <ip_address2>}
。
目前,我有这样的代码:
for hostname in ${hostnames[@]}; do
# Doing something.
hostname_ip +=`(echo $var|xargs)`
done
然后我要使用主机名:
for the hostname in $hostnames; do
# Doing something with `hostname`.
Also, for some reason, I need the IP address for exact host here.
But I have no idea how to extract it properly in bash...
也许在bash中映射不是最好的主意,但是我没有更好的主意...