Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: here document within a switch fails to parse.



On 2021-01-08 7:53 a.m., Lawrence Velázquez wrote:
On Jan 8, 2021, at 10:27 AM, Karsten Borgwaldt <kb@xxxxxxxxxx <mailto:kb@xxxxxxxxxx>> wrote:

Some expressions in heredocs will be evaluated. Not a good idea for comments:

:<<EOC
$(print something > /dev/stderr)
EOC

Not if some or all of the delimiter specification is quoted (as Ray is doing, in response to a suggestion in an earlier thread):

: <<\EOC
$(print something > /dev/stderr)
EOC

Good to know!  But playing with the above:

function test1 ()
{
:<<EOC
$(print something from a function with dollarsign)
print something from a function redirected > /dev/stderr
$(print something from a function both > /dev/stderr)       # This is the only thing that prints.
print something from a function
COMMENT from a function
echo "echo from a function"
EOC
}

... not to belabor it, but why in heaven is just that one construction evaluated?  zsh always has a gotcha! waiting, but someone obviously went to some trouble to sniff that out. Neither the '$' nor the redirection is sufficient alone but they evaluate together.  Why? I'd better read up on what here documents are really for. And it isn't comments!  But when I want to quickly turn off a hundred lines of code, I succumb to the temptation.







Messages sorted by: Reverse Date, Date, Thread, Author