Bash:如何使用for循环创建映射?

时间:2018-10-18 21:24:59

标签: bash dictionary mapping

我正在尝试用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中映射不是最好的主意,但是我没有更好的主意...

0 个答案:

没有答案