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

Re: Why are empty elements removed from array expansion?



On Dec 22,  9:46pm, Nikolai Weibull wrote:
} Subject: Why are empty elements removed from array expansion?

To understand this, you have to go all the way back to about 1992
when zsh was first being written.

Zsh was designed to make interactive csh users feel comfortable with 
the more rigorously parsed Bourne shell syntax.  In /bin/sh, the only
arrays are $* and its fraternal twin $@, so the behavior of those
variables became the prototype for the behavior of all arrays.

Implicit word splitting of expanded strings was one of the things that
bothered Paul Faulstad about the Bourne shell, but a side-effect of
splitting is that if you first join an array and then split it again,
the empty elements vanish.  So in order to make $* behave in zsh the
way it _appears_ to behave in /bin/sh, empty elements have to vanish.
And because $* is the prototype for all array expansions, all arrays
behave that way.

This is thus a "principle of least surprise" issue -- not what least
surprises *you*, as a programmer expecting certain rigid rules, but
what least surprises an inexpert shell user trying to figure out why
"cat $a" says that the empty string can't be opened as a file.



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