ksh关联数组 [英] ksh associate arrays

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

问题描述

我有一个需要使用关联数组的脚本.作为ksh的新手,我无法找到ksh支持关联数组的任何地方.当我尝试使用常规数组语法并进行赋值时,出现一个错误,即索引不能那么大. ksh是否支持关联数组?如果没有,替代解决方案是什么?

I have a script that needs to use associative arrays. Being new to ksh, I am unable to find anywhere that ksh supports associative arrays. When I try to use regular array syntax and assign, I get an error that index cannot be that big. Does ksh support associative arrays? If not, what is the alternative solution?

我需要执行以下操作:

${array[$name]}=value

以及随后的代码中,读取

and later in the code, to read a value for

${array[$name]}

每次运行此脚本时,大约有2000个值要存储并从数组中读取.

I have about 2000 values to be stored and read from the array every time this script runs.

不幸的是,由于脚本中包含的遗留模块的范围,我无法使用perl.感谢任何帮助,技巧或技巧.

Unfortunately, I cannot use perl due to the extent of legacy modules to be included inside the script. Appreciate any help, tips or techniques.

推荐答案

ksh typeset命令用于声明关联数组.

The ksh typeset command is used to declare an associative array.

$ typeset -A age
$ age[bob]=42
$ age[alice]=31
$ print ${age[bob]}
42

这篇关于ksh关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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