user3437245
user3437245

Reputation: 347

Error on bash in loop

Trying to prepend all files in a directory with

line1
line2
line3

with this command:

$ for i in $(ls) ; perl -pi -e 'print "line1 \nline2\nline3\n" if $. == 1' $i ; done

but I have this error:

bash: syntax error near unexpected token `perl'

perl command works for single file. Any explanation for the error?

Upvotes: 3

Views: 37

Answers (1)

Kristianmitk
Kristianmitk

Reputation: 4778

You are missing the do...

for i in $(ls); 
do
    perl -pi -e 'print "line1 \nline2\nline3\n" if $. == 1' $i ; 
done

Upvotes: 4

Related Questions