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

Re: comment block curiosity



On Mon, Jan 4, 2021 at 9:09 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2021-01-03 10:10 p.m., Daniel Shahaf wrote:
> >
> > % zsh -f =(print -rC1 -- 'alias -g "|&"=": <<EOC"' 'echo foo' '|&' 'echo bar' 'EOC' 'echo baz')
>
> That is an invocation only an Adeptus dare use!

A somewhat more readable variation:

% zsh -f =(<<\EOSCRIPT
alias -g "|&"=": <<EOC"
echo foo
|&
echo bar
EOC
echo baz
EOSCRIPT
)

Also, "print -C1" is the same as "print -l" if that makes it more obvious.

> > ... The lexer doesn't emit a token for comments ...
> Is there some way of seeing lexer output?

You get that from
  setopt xtrace
but redirections (including here-documents) are also omitted.
  setopt verbose
gets the contents of the here-document, but neither of those setopts
shows expanded aliases, so with the "|&" alias in place you can't see
the "<<EOC" operator itself.

You can also get a lexical breakdown by using the (z) or (Z+c+)
parameter expansion flags, but those also do not expand aliases and
don't know about here-documents so you get the contents of the
here-document parsed into tokens as well.  I suppose the latter could
be considered a bug.




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