Answer:First, the heredoc could be listed last without affecting what happens. Heredocs are traditionally written last but the
<<NAMEbut can actually be written anywhere within the command. The order of
<<relative to the two
>redirections doesn’t matter since the former changes stdin and the latter change stdout and stderr.
It’d be clearer if it were written:
ftp -v -n > /tmp/ftp$$ 2>&1 <<! ... ! [/code]Second, to explain the output redirections:
> /tmp/ftp$$redirects stdout to a file named
1234is the PID of the current shell process. It’s an ad hoc way of making a temporary file with a relatively unique name. If the shell script were run several times in parallel each copy would write to a different temp file.
2>&1redirects stderr (fd 2) to stdout (fd 1). In other words, it sends error messages to the same file
If you have better answer, please add a comment about this, thank you!