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.
3 Answers 3
try un-indenting your eof:
function {
while read file;
do
echo $file;
done << eof
$(ls)
eof;
}
Comments
Don't indent your heredoc, and your eof marker should not have a trailing semicolon
Comments
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 () { ... } )