Multiline syntax for piping a heredoc; is this portable?

前端 未结 4 1510
北恋
北恋 2020-12-12 14:54

I\'m familiar with this syntax:

cmd1 << EOF | cmd2
text
EOF

but just discovered that bash allows me to write:

cmd1 &         


        
4条回答
  •  借酒劲吻你
    2020-12-12 15:17

    Yes it's in the POSIX shell grammar. You can also have more than one here-doc for the same command (some other examples use two cat invocations, but this works as well):

    cat <

    This is contrived (using 2 here-docs for stdin), but if you think of providing input for different file descriptors it immediately makes sense.

    There's also the possibility to drop the cat entirely. Why not make the here-document directly available to cmd:

    cmd << EOF
    input
    here
    EOF
    

提交回复
热议问题