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

${(S)%%*} doesn't match the empty string (was: Re: [PATCH] zshexpn: Expand documentation of (S) (was: Re: [Bug] S-flag imposes non-greedy match where it shouldn't))



Sebastian Gniazdowski wrote on Mon, Dec 30, 2019 at 21:20:34 +0100:
> On Mon, 30 Dec 2019 at 21:01, Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
> > I think it would be beneficial to specify that with ${(S)str##pattern}
> > the first attempted match starts at str[-1] and that no attempt is
> > made to check if the empty string (the ultimate shortest suffix)
> > matches. I think you or someone else has recently raised this point as
> > this seems inconsistent. It's surprising to me that both ${str#*} and
> > ${(S)str%*} expand to $str while ${(S)str%%*} doesn't.
> 

Let's see:

     1	% set -- foo
     2	% p ${1#*}
     3	foo
     4	% p ${1%*}
     5	foo
     6	% p ${(S)1#*}
     7	foo
     8	% p ${(S)1%*}
     9	foo
    10	% p ${1##*}
    11	
    12	% p ${1%%*}
    13	
    14	% p ${(S)1##*}
    15	
    16	% p ${(S)1%%*}
    17	fo
    18	% 

Isn't this an implementation bug?  It certainly would be if the docs patch
I posted is accepted.  The existing documentation doesn't promise this behaviour
either.

> Also, ${str%*} doesn't expand to $str,

It does for me; see above.

> which seems to be a bug? Is it a different uncover of the one from
> users/22600?



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