I’m familiar with this syntax:
cmd1 << EOF | cmd2
text
EOF
but just discovered that bash allows me to write:
cmd1 << EOF |
text
EOF
cmd2
(the heredoc is used as input to cmd1, and the output of cmd1 is piped to cmd2). This seems like a very odd syntax. Is it portable?
Yes, the POSIX standard allows this. According to the 2008 version:
And includes this example of multiple “here-documents” in the same line:
So there is no problem doing redirections or pipes. Your example is similar to something like this:
And the shell grammar (further down on the linked page) includes these definitions:
So a pipe symbol can be followed by an end-of-line and still be considered part of a pipeline.