在shell脚本关联数组 [英] Associative arrays in Shell scripts
本文介绍了在shell脚本关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们需要模拟关联数组脚本或地图像Shell脚本,任何机构?
We required a script that simulates Associative arrays or Map like data structure for Shell Scripting, any body?
推荐答案
要添加到伊尔凡的回答,这里是一个更短,更快的版本的get()
,因为它需要在地图内容概不迭代:
To add to Irfan's answer, here is a shorter and faster version of get()
since it requires no iteration over the map contents:
get() {
mapName=$1; key=$2
map=${!mapName}
value="$(echo $map |sed -e "s/.*--${key}=\([^ ]*\).*/\1/" -e 's/:SP:/ /g' )"
}
这篇关于在shell脚本关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文