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

Re: treatment of empty strings - why is this not a bug?



On Thu, 15 Jan 2009 20:29:29 +0000
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> Greg Klanderman wrote:
> > I still do not understand why I get exactly two empty strings no
> > matter how many colons I have in the input string: I would expect
> > none based on the description you cited.
> > 
> > phl% x=::::: && for v in "${(s-:-)x}" ; do echo "v= =>$v<=" ; done
> > v= =><=
> > v= =><=
> > phl% x=: && for v in "${(s-:-)x}" ; do echo "v= =>$v<=" ; done 
> > v= =><=
> > v= =><=
> 
> It's to do with the code that joins parameters with what's next to them,
> which is why the RC_EXPAND_PARAM option is different.

Actually, I think I can do better than that.  It's because quoted NULLs
never disappear---the only things that disappear are the empty fields
resulting from the splitting.  You can therefore think of the key
expression in the foregoing as

  ""${(s-:-)}""

(two double-quoted NULLs bookending an expression split into an
array---this isn't how it works internally, but the effect is very similar.)
Now you can see the distinction from having no quotes in the expression
at all.  So in the case where RC_EXPAND_PARAM is unset what remains are the
NULLs at each end; with it set, those get combined with all the fields in
the middle.  It does have its own twisted logic.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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