击:坏数组下标 [英] Bash: bad array subscript

查看:136
本文介绍了击:坏数组下标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 线程=`LS T [0-9] [0-9]`在线程$ {线程[@]}

       回声$线
DONE

预期结果:

  T01
T02
T10

实际结果:

 线程[@]:坏的数组下标


解决方案

说:

 线程=`LS T [0-9] [0-9]`

 线程= \\`LS T [0-9] [0-9] \\`

创建一个数组。

为了创建一个数组,说:

 线程=(LS T [0-9] [0-9])

此外,避免解析LS

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

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

Expected result:

t01
t02
t10

Actual Result:

threads[@]: bad array subscript

解决方案

Saying:

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

or

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

does not create an array.

In order to create an array, say:

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

Moreover, avoid parsing ls.

这篇关于击:坏数组下标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆