Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Block comments ala Ray
- X-seq: zsh-workers 48023
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Lawrence Velázquez <vq@xxxxxxxxx>
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: Block comments ala Ray
- Date: Fri, 12 Feb 2021 21:02:36 +0000
- Archived-at: <https://zsh.org/workers/48023>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-02/20210212210236.rsmrs65lmtxzoqzc%40chazelas.org>
- In-reply-to: <B2B62C95-EEDF-442A-9ACA-75EE653CEB72@larryv.me>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Lawrence Velázquez <vq@xxxxxxxxx>, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, zsh-workers@xxxxxxx
- References: <CAH+w=7YZREq7FbJCCoWoJ-vQ7+P5Z=_mKB-aStoMiBRupqD_wA@mail.gmail.com> <CAN=4vMonpZHPSarsC778_GMbD_h4ioTwT+bTFU=FZ7_zbXaMqQ@mail.gmail.com> <CAH+w=7Zd2gY-s5T1dDNEEujAh6197MzrUD-iZrVwZLzD=L7xVQ@mail.gmail.com> <CAN=4vMoYj3WbBk3BL98buiYcf7rkLtw=b9v_f0p1C4zqYRB7xg@mail.gmail.com> <20210212074031.7746vg37xykniem5@chazelas.org> <CAH+w=7ZT3vgGVd_NAndnDt2zbLwGV3Pwu=7+utEuwvSkKd4jOA@mail.gmail.com> <20210212154547.iy35rp4ijaef22ld@chazelas.org> <CAH+w=7bLXK_rZPsx33BTyKb5Q43uPc3W4Ayf0A8Gfkik0W9r9A@mail.gmail.com> <B2B62C95-EEDF-442A-9ACA-75EE653CEB72@larryv.me>
2021-02-12 13:16:28 -0500, Lawrence Velázquez:
[...]
> This was me, addressing someone with shaky shell fundamentals who
> was aliasing the here-document idiom and expecting it to behave
> identically to real comments (discarded during lexing, no further
> impact on the script).
[...]
Thanks all for the clarifications.
About "discarding during lexing", I did find these btw:
$ ksh93 -c $'f() {\n# whatever\necho x\n}; typeset -f f'
f() {
# whatever
echo x
}
It appears as if they're not discarded(though it looks like it's
rather that ksh stores the raw text content (probably only for
the "typeset -f" output) in addition to "compiling"/"wordcoding"
or however you want to call it (which probably still discards
comments)).
But see also (as that construct was mentioned in that thread):
$ zsh -c 'f() { echo `echo x # comment`; }; typeset -f f; f'
f () {
echo `echo x # comment`
}
x
$ mksh -c 'f() { echo `echo x # comment`; }; typeset -f f; f'
f() {
\echo $(echo x # comment)
}
x
$ bash -c 'f() { echo `echo x # comment`; }; typeset -f f; f'
f ()
{
echo `echo x # comment`
}
x
as the parsing of the inside of `...` is deferred in all shells
except ash-based ones; see $shell -c ':||echo `for`'. A bit like
in eval 'echo x # comment'.
It's also deferred with the $(...) form in bash (but bash only
AFAICT):
$ bash -c $'f() { echo $(echo x # comment\n); }; typeset -f f'
f ()
{
echo $(echo x # comment
)
}
That newline is necessary in all shells though there, and that
makes the replacing of `...` with $(...) in the typeset -f
output by mksh above incorrect:
~$ mksh -c 'f() { echo `echo x # comment`; }; typeset -f f' | mksh
mksh: <stdin>[3]: syntax error: unexpected '}'
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author