当前位置: 技术问答>linux和unix
shell 中有没有二维数组
来源: 互联网 发布时间:2016-02-13
本文导语: 请教 shell 中有没有二维数组 如何实现的 | Perl的话, $a1 = [ [ "11", "12", "13", ], [ "21", "22", "23", ], [ "31", "32", "33", ], ]; pri...
请教
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];
$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]}
#!/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]}