日期:2014-05-16  浏览次数:20707 次

shell 中有没有二维数组
请教 
shell 中有没有二维数组
如何实现的

------解决方案--------------------
Perl的话,
$a1 = [
[ "11", "12", "13", ],
[ "21", "22", "23", ],
[ "31", "32", "33", ],
];
print $a1->[2][2];
或者
@a2 = (
[ "11", "12", "13", ],
[ "21", "22", "23", ],
[ "31", "32", "33", ],
);
print $a2[2][2];


------解决方案--------------------
KSH模拟的例子:

#!/bin/ksh

i=1
j=1
COL=3
typeset -A b
cat data|xargs -n1|while read a; do
b[${i}"x"${j}]=$a
if [ $j -ge $COL ]; then
j=1
let i++
else
let j++
fi
done
echo print two values in [2,3] and [3,3]
echo ${b[2x3]}
echo ${b[3x3]}