Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Why do we need to quote # in ${(#):-2\#1011010} ?
On Sun, Sep 12, 2021 at 1:12 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> $ echo ${:-2#1011010}
> 2#1011010
>
> That # is fine when not quoted there, so why:
> [...]
> It seems to discard everything after the expansion within the word:
>
> $ echo before${(#):-2#1011010}"hey, where did that go?" other args
> before other args
The short answer is that ${(#):-2#1011010} should give a parse error
on the number-to-character conversion, but doesn't. In the first
case, without (#), there's no parse so there's no error, which is why
it doesn't need the backslash. I suppose paramsubst() should be
calling zerr() somewhere near here:
3553 noerrs = one;
3554 if (!quoteerr) {
3555 /* Retain user interrupt error status */
3556 errflag = oef | (errflag & ERRFLAG_INT);
3557 }
3558 if (haserr || errflag)
3559 return NULL;
The other option would be to unmetafy somewhere before calling
substevalchar() but since multsub() also sometimes unmetafies, it's
not clear when to do so. Or perhaps something upstream is
unnecessarily over-metafying when the # is not escaped?
More details (just notes as I step through with gdb):
FAILING CASE
We arrive in paramsubst() with
"\205\217\210\204\212:\233\062\204\061\060\061\061\060\061\060\220\236hey,
where did that go?\236"
val becomes "2\204\061\060\061\061\060\061\060" at line 2948
multsub() does nothing, so substevalchar() returns NUL at 3550 and haserr = 1
so paramsubst() returns NULL as does stringsubst(), but without an errflag
and prefork() bails out at line 146, which truncates the word.
WITHOUT (#)
"\205\217:\233\062\204\061\060\061\061\060\061\060\220\236hey, where
did that go?\236"
Everything is the same as the failing case except that substevalchar()
is never called, so there's no error, and the result is simply
unmetafied and returned.
WITH BACKSLASH / WORKING
"\205\217\210\204\212:\233\062\237#1011010\220\236hey, where did that go?\236"
val becomes "2\237#1011010"
multsub() unmetafies it to "2#1011010" and substevalchar() returns "Z"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author