ksh associate array

2019-06-21 11:29发布

问题:

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