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

Re: Word splitting in zsh

(Distribution changed to -workers)

On Feb 9, 10:34am, Andrej Borsenkow wrote:
} > zagzig% echo $ZSH_VERSION
} > 3.1.9-dev-8
} > zagzig% set "a1 a2 a3" b c
} > zagzig% print -l ${1+"$@"}
} > a1 a2 a3 b c						<-- Yipes!
} Well, this is "correct" *zsh* behaviour. The part after `+' is a word - not
} array. And is taken as single word and is never splitted. What happens here,
} is
} - zsh evaluates "$@" that gives you array with three elements
} - but because of "scalar context" in this case (the best I can call it) array
} is concatenated forming the above value.

Yes, your analysis is correct; the bug is that there should not be a scalar
context there.  The effect of ${NAME:+WORD} and ${NAME:-WORD} should be to
replace the context of NAME with the context of WORD in the event that NAME
is (or not) set.  Put another way, the type of NAME should only determine
the type of the whole ${...} when NAME really is being substituted.

(One could argue, then, that ${NAME:=WORD} should make NAME into an array if
WORD expands to an array.  In fact, there are a number of things that this
would make simpler, though there also may be some things it would break.)

} Even worse, it is inconsistent with everything else - array joining is
} supposed to use IFS ... but it does not in this case.

Well, that ought to be relatively simple to fix, and probably isn't even
widely depended-upon.  Zsh scripts hardly ever bother fooling with IFS,
given all the other ways that one has to chop up strings.

} > I don't know exactly when this bug was introduced, though.
} That is almost inevitable in current implementation.

Yes, but 3.0.6 doesn't *have* the current implementation, and it's got
the same problem as demonstrated for 3.0.8 in my previous message.  So
part of this got introduced quite some time ago, which is what I meant.

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   

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