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

Re: Field splitting: extra empty field with final non-whitespace IFS character



On Jun 22,  5:06am, Martijn Dekker wrote:
}
} % emulate sh
} % IFS=':'
} % x='a:b::'
} % set -- $x
} % echo $#
} 4
} 
} zsh counts 4 fields instead of 3, like most other shells do.

I don't really like the following patch because it's testing SHWORDSPLIT
at such a low level.  I *think* spacesplit() is called only for field
splitting, for which SHWORDSPLIT explicitly applies, so it's probably
OK, but there might be a code path I haven't found where this could
leak over into to word splitting (where SHWORDSPLIT should NOT apply).

A similar change woule be needed in bin_read(), but I haven't made the
attempt yet to figure out where amidst all the multibyte handling and
metafication the final empty-string element is assigned.

diff --git a/Src/utils.c b/Src/utils.c
index 13fc96a..f0a92d2 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3208,7 +3208,7 @@ spacesplit(char *s, int allownull, int heap, int quote)
 	    *ptr = (heap ? (char *) hcalloc((s - t) + 1) :
 		    (char *) zshcalloc((s - t) + 1));
 	    ztrncpy(*ptr++, t, s - t);
-	} else
+	} else if (*s || !isset(SHWORDSPLIT))
 	    *ptr++ = dup(nulstring);
 	t = s;
 	skipwsep(&s);

-- 
Barton E. Schaefer



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