Bash:坏数组下标

时间:2014-01-28 08:16:13

标签: arrays bash for-loop

threads=`ls t[0-9][0-9]`       

for thread in "${threads[@]}"
do
       echo $thread
done

预期结果:

t01
t02
t10

实际结果:

threads[@]: bad array subscript

1 个答案:

答案 0 :(得分:2)

话说:

threads=`ls t[0-9][0-9]`

threads=\`ls t[0-9][0-9]\`

创建数组。

为了创建一个数组,请说:

threads=(ls t[0-9][0-9])

此外,avoid parsing ls