Translate

Archives

Korn Shell Multidimensional Arrays

The bash shell only supports single dimension arrays. Korn Shell 93 (ksh93), on the other hand, supports multidimensional arrays although this feature is poorly documented. Here is a simple example which demonstrates how to create and use a multidimensional array: #!/bin/ksh93 for i in 1 2 3 do for j in 4 5 6 do for k in 7 8 9 do array[$i][$j][$k]=$(( i + j + k )) # echo ${array[$i][$j][$k]} done done done for i in 1 2 3 do echo ${array[$i][4][7]} done It outputs: 12 13 14 Note – multidimensional associative arrays are not supported.