2014-01-10 122 views
0

這是什麼錯誤?bash while循環中的語法錯誤

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循環的錯誤,我測試了好機器,但同樣的問題上

+0

請閱讀http://stackoverflow.com/help/someone-answers –

回答

1

使用for loop

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

在bash中我仍然是虛擬的,你能爲我整個循環嗎? – user3178889

+1

@ user3178889這完全是另一回事,會讓你錯失寶貴的學習機會。我們都是一次假人。 –

1

問題是,您正在使用bash特定<(process substition),但運行喲你的腳本與/bin/sh

使用bash script.sh,而不是sh script.sh,並確保家當使用bash和不SH。