3

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?

1
  • shellcheck automatically points out your missing do Commented Apr 2, 2018 at 23:18

1 Answer 1

4

You are missing the do...

for i in $(ls); 
do
    perl -pi -e 'print "line1 \nline2\nline3\n" if $. == 1' $i ; 
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.