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

On "the usual behaviour" of empty array elements



A fairly recent addition to the doc for the (s::) parameter flag is this:

     For historical reasons, the usual behaviour that empty array
     elements are retained inside double quotes is disabled for arrays
     generated by splitting

The thing is, I can't find anywhere else that "the usual behavior" of
empty array elements is even mentioned.

Far more interesting than the retention of empty array elements in double
quotes, I think, is that empty array elements are NOT retained when the
array parameter reference is NOT in quotes.  (This is intended to mimic
one useful effect of word splitting without bringing in all the other
effects.)  This is a significant detail of the way no_sh_word_split
works, but there's not so much a passing reference to it in "General
Comments on Syntax":

  One commonly encountered difference is that variables substituted onto
  the command line are not split into words.  See the description of the
  shell option SH_WORD_SPLIT

(Which itself seems awfully short shrift to give to that topic.)

"Parameter Expansion" just repeats:

  Note in particular the fact that words of unquoted parameters are not
  automatically split on whitespace unless the option SH_WORD_SPLIT is
  set; see references to this option below for more details.

The closest thing to an explanation is this bit of the FAQ:

  Note also the "$@" method of word splitting is always available in zsh
  functions and scripts (though strictly this does array splitting, not
  word splitting).  This is more portable than the $*, since it
  will work regardless of the SH_WORD_SPLIT setting; the other
  difference is that $* removes empty arguments from the array.

But that hardly makes it clear that every unquoted array expansion gets
treated this way.  Is there something I just haven't spotted?  I confess
I merely searched the doc rather than re-read it cover to cover.



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