Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on bash in loop

Tags:

bash

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?

like image 836
user3437245 Avatar asked Mar 11 '26 06:03

user3437245


1 Answers

You are missing the do...

for i in $(ls); 
do
    perl -pi -e 'print "line1 \nline2\nline3\n" if $. == 1' $i ; 
done
like image 88
Kristianmitk Avatar answered Mar 14 '26 03:03

Kristianmitk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!