Bash: bad array subscript

后端 未结 1 1241
忘掉有多难
忘掉有多难 2021-01-29 11:52
threads=`ls t[0-9][0-9]`       

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

Expected result:

t01
t02
t10
1条回答
  •  情歌与酒
    2021-01-29 12:09

    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.

    0 讨论(0)
提交回复
热议问题