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

Re: ${^var} and word splitting



On Mon, 24 Nov 2014 15:26:28 +0000
Stephane Chazelas <stephane.chazelas@xxxxxxxxx> wrote:
> If I understand correctly, in zsh the removing of those are
> accounted to null-removal in things like:
> 
> $ print -l $=a
> 1
> 2
> 3
> 
> But then it's not clear why they are removed there and not in:
> 
> a=':a::b:'
> IFS=:
> print -l $=a

I looked at the code and you're exactly right: it's not clear.  There's
a parameter determining how the split function behaves and there's an
argument allownull that I already noted I didn't understand in the
comment to sepsplit(), determining whether the argument being set will
be empty or will be set to something that has no effect except
preventing the argument being removed later.  In the case in question
this is zero.

Consequently it's easy to change the behaviour in the second case...
This doesn't cause any test failures.  Unless anyone has any ideas why
we do this, maybe we should simplify it like this?  If anyone does have
ideas, we should write a test for that case.

There's one other case in parameter substitution to do with assignment
within the substitution that presumably ought to be consistent.

diff --git a/Src/subst.c b/Src/subst.c
index 61aa1c1..17f35be 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3322,7 +3322,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags)
 	    isarr = 0;
 	}
 	if (!ssub && (spbreak || spsep)) {
-	    aval = sepsplit(val, spsep, 0, 1);
+	    aval = sepsplit(val, spsep, 1, 1);
 	    if (!aval || !aval[0])
 		val = dupstring("");
 	    else if (!aval[1])

pws



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