【问题标题】:Bash: bad array subscriptBash:错误的数组下标
【发布时间】:2014-02-19 10:22:06
【问题描述】:
threads=`ls t[0-9][0-9]`       

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

预期结果:

t01
t02
t10

实际结果:

threads[@]: bad array subscript

【问题讨论】:

  • 另外,您可能想要真正提出问题,而不是仅仅提交代码......

标签: arrays bash for-loop


【解决方案1】:

说:

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

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

创建数组。

为了创建一个数组,说:

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

另外,avoid parsing ls

【讨论】:

    猜你喜欢
    • 2020-12-29
    • 2013-04-13
    • 1970-01-01
    • 2018-01-28
    • 2018-02-12
    • 1970-01-01
    • 2014-02-19
    • 2017-07-18
    相关资源
    最近更新 更多