Shell 脚本中的关联数组 [英] Associative arrays in Shell scripts

查看:27
本文介绍了Shell 脚本中的关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要一个脚本来模拟关联数组或类似映射的数据结构的 Shell 脚本,任何正文?

We required a script that simulates Associative arrays or Map like data structure for Shell Scripting, any body?

推荐答案

要添加到 Irfan 的答案,这里有一个简短的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆