I am automating an ftp session, but I want to take stdout and pipe it to file. I have come up with 3 options:
Option 1
ftp -i ftpServer >stdoutFile <<EOF
cd somewhere
get something
EOF
ftp -i ftpServer <<EOF >stdoutFile
cd somewhere
get something
EOF
ftp -i ftpServer <<EOF
cd somewhere
get something
EOF > stdoutFile
if [ condition ]
then
ftp -i ftpServer >stdoutFile <<EOF
cd somewhere
get something
EOF
fi
if [ something else ]
then
somethingWithaHereDoc <<EOF
foo
bar
EOF
fi
Syntax error near unexpected token 'fi'
The <<EOF
only signals that a here document will begin on the next line. You can freely mix this with other redirections, so options 1 and 2 are both valid. There is no difference between the two, although I suspect most people would prefer and suggest option 1, as it does not appear to "interject" the output redirection into the here document.
If you are getting syntax errors with either option 1 or option 2, they are almost certainly unrelated to the here document itself.
Option 3 is invalid because the here document delimiter must occur on a line by itself, and because it is not part of the original command.