shell实现多字典条目遍历
#!/bin/bash
#必须先声明
declare -A dic0
declare -A dic1
declare -A dic2
declare -A dic3
dic0=([ip]="192.168.56.120" [m_pwd]="xxxxxx" [r_pwd]="xxxxxx")
dic1=([ip]="192.168.56.121" [m_pwd]="xxxxxx" [r_pwd]="xxxxxx")
dic2=([ip]="192.168.56.122" [m_pwd]="xxxxxx" [r_pwd]="xxxxxx")
dic3=([ip]="192.168.56.123" [m_pwd]="xxxxxx" [r_pwd]="xxxxxx")
ALL=(0 1 2 3)
for ip in ${ALL[@]}
do
eval echo '$'"{dic${ip}["ip"]}"
eval echo '$'"{dic${ip}["m_pwd"]}"
eval echo '$'"{dic${ip}["r_pwd"]}"
done
也许我已经迷失很久了,早已丢失了自己的影子。