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

Re: Block comments ala Ray



2021-02-12 13:29:48 -0800, Bart Schaefer:
> On Fri, Feb 12, 2021 at 1:12 PM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> >
> > But still, the comments appear not to be discarded at that point:
> >
> > $ zsh -c $'f() { echo $(echo x # comment\n); }; typeset -f f; f'
> > f () {
> >         echo $(echo x # comment
> > )
> > }
> > x
> 
> The literal text of what's contained in $(...) is retained
[...]

You're right. It looks like the contents is parsed (I suppose to
be able to handle the case x in x)... and the like inside), but
the result of that parsing seems to be discarded, and it seems
the contents of that $(...) is parsed again each time the
function is invoked.

ksh93 does appear to do the same. bash as well, but it's unclear
to me what kind of parsing it does in the first round.

See for instance:

$ bash -xc 'echo $(foo case a in a); esac)'
++ foo case a in a
bash: foo: command not found
+ echo '; esac)'
; esac)

-- 
Stephane




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