ksh associate array

佐手、 提交于 2019-12-10 14:18:16

问题


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?

need to do the following: ${array[$name]}=value and later in the code, I need to read value for ${array[$name]}. I have about 2000 values to be stored and read from the array everytime script runs.

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


回答1:


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

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


来源:https://stackoverflow.com/questions/4394894/ksh-associate-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!