user3178889
user3178889

Reputation: 729

Syntax Error in bash while loop

What is the error in that?

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)

Out:

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

Really i don't know the error in that while loop, i tested it on several machine but same problem

Upvotes: 0

Views: 91

Answers (2)

that other guy
that other guy

Reputation: 123500

The problem is that you're using bash specific <(process substition), but running your script with /bin/sh.

Use bash script.sh instead of sh script.sh, and make sure the shebang uses bash and not sh.

Upvotes: 2

kurumi
kurumi

Reputation: 25609

use a for loop

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

Upvotes: 1

Related Questions