Posts

Showing posts with the label heredoc

Why are heredoc redirections not allowed before a while loop

Image
Clash Royale CLAN TAG #URR8PPP Why are heredoc redirections not allowed before a while loop The POSIX Shell Command Language allows redirections to follow compound commands. The standard says (emphasis mine) The shell has several programming constructs that are "compound commands", which provide control flow for commands. Each of these compound commands has a reserved word or control operator at the beginning, and a corresponding terminator reserved word or operator at the end. In addition, each can be followed by redirections on the same line as the terminator . Each redirection shall apply to all the commands within the compound command that do not explicitly override that redirection. For aesthetic reasons I want to put a heredoc before my while loop as in <<'RECORDS' while foo:bar baz:quux ... RECORDS IFS=: read -r A B do # do something with A and B done because it makes the code easier to follow. However, it doesn't work in the shells I tried it (...