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
 

posted @ 2021-01-13 10:09  JcLevy  阅读(867)  评论(0编辑  收藏  举报