0

i want run a bash shell script like this:

while read file;

do

 echo $file;

done << eof

$(ls)

eof;`

it work well in a sample .sh file. but when put this in a function like:

function {
 while read file;
 do
 echo $file;
 done << eof 
 $(ls) 
 eof;
}

it not work for me.

i dont know how to fix it now.

0

3 Answers 3

1

try un-indenting your eof:

function {
 while read file;
 do
 echo $file;
 done << eof 
 $(ls) 
eof;
}
answered Jan 28, 2013 at 11:50
Sign up to request clarification or add additional context in comments.

Comments

1

Don't indent your heredoc, and your eof marker should not have a trailing semicolon

answered Jan 28, 2013 at 11:51

Comments

1

In bash : use <<-TERMINATION if you want it to ignore whitespaces before the TERMINATION string (but if you prefer compatibility, use <<TERMINATION and have TERMINATION alone on a line, and starting at the first column. If the trailing ; is a problem too, put it on the next line (or put a : ; if you prefer)

And give a name to your function : function myfunction { ... } (or, more compatible : myfunction () { ... } )

answered Jan 28, 2013 at 14:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.