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

Re: z parameter expansion flag is broken?



On Sep 9,  4:13am, Yuya Amemiya wrote:
}
} Why does z parameter expansion flag remove leading '-' from result?

Hrm.

In the (z) case, "-" has been tokenized as DASH when bufferwords() is
called.  This eventually comes down to ingetc() while reading the next
lexical word from the input buffer.  At line 202 there is

202                 if (itok(lastc = STOUC(*inbufptr++)))
203                     continue;

Because itok(DASH) is true, we discard it and continue around the loop.

That code in ingetc() is as old as the shell itself, so I have to assume
that there's a good reason to discard token characters during lexing,
and the problem is upstream with the recently-introduced code that
more aggressively tokenizes hyphens ... though I don't understand why
other tokens haven't similarly been adversely affected (or maybe I just
haven't found how to get another token embedded in the string).

In any case this is a really serious bug; it's not just leading "-" that
get removed:

torch% print -r -- ${(z):--a -b -c d-e-f}
a b c def



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