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

Re: shwordsplit: final non-whitespace IFS character problem



2017-08-04 04:03:19 +0200, Martijn Dekker:
> In field/word splitting, a final non-whitespace IFS delimiter character
> is counted as an empty field. This is unlike every other current shell
> (including current versions of pdksh, i.e. mksh and OpenBSD ksh).
> 
> Test script:
> 
> setopt shwordsplit
> IFS=:
> x=a:b:
> set -- $x
> echo $#
[...]

IIRC, it was discussed before, and the concensus at the time was
that it would be silly as the S in IFS stands for *S*eparator, not
terminator nor delimiter. At the time though, a number of shells
(pdksh and ash based ones) still behaved like zsh and not ksh88
and POSIX was even less clear about it.

Note that, it also affects "read", where "IFS=: read var" on an
output that contains "word:" should (as per POSIX) store "word"
into "var" (while it "should" store "word1:word2:" on a line
with "word1:word2:").

I can't imagine changing the behaviour in the sh/ksh emulations
would be a problem (though I still think it's silly).

Note that with that semantic, you can no longer do things like:

IFS=:
set -o noglob
for dir in $PATH; do
  ...
done

You need to use some kludge like the "which" POSIX script does
on Debian to account for PATHs like "/bin:/usr/bin:".

-- 
Stephane



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