bash while循环中的语法错误

时间:2014-01-10 00:20:54

标签: bash

那是什么错误?

j=0
filenames=("")
filedates=("")

while read line
do
filenames[$j]="$line"
filedates[$j]=$(stat -c %y ${filenames[$j]} | cut -d ' ' -f1)
(( j++ ))
done < <(ls -t *.gz)

输出:

script.sh: line 9: syntax error near unexpected token `<'
script.sh: line 9: `done < <(ls -t *.gz)'

真的我不知道while循环中的错误,我在几台机器上测试但是同样的问题

2 个答案:

答案 0 :(得分:1)

使用for loop

for file in *t.gz
do
   ...
done

答案 1 :(得分:1)

问题是您使用bash特定<(process substition),但使用/bin/sh运行脚本。

使用bash script.sh代替sh script.sh,并确保shebang使用bash而不是sh。