zsh-workers
 help / color / mirror / code / Atom feed
* On "the usual behaviour" of empty array elements
@ 2012-07-07 17:37 Bart Schaefer
  2012-08-05  7:09 ` Nikolai Weibull
  2012-08-06 16:04 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Bart Schaefer @ 2012-07-07 17:37 UTC (permalink / raw)
  To: zsh-workers

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: On "the usual behaviour" of empty array elements
  2012-07-07 17:37 On "the usual behaviour" of empty array elements Bart Schaefer
@ 2012-08-05  7:09 ` Nikolai Weibull
  2012-08-06 16:04 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Nikolai Weibull @ 2012-08-05  7:09 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On Sat, Jul 7, 2012 at 7:37 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:

> 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 behavior has really surprised me in the past.  I’m guessing
there’s no way to remove this behavior?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: On "the usual behaviour" of empty array elements
  2012-07-07 17:37 On "the usual behaviour" of empty array elements Bart Schaefer
  2012-08-05  7:09 ` Nikolai Weibull
@ 2012-08-06 16:04 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2012-08-06 16:04 UTC (permalink / raw)
  To: zsh-workers

On Sat, 07 Jul 2012 10:37:22 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> 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.
>
> Is there something I just haven't spotted?  I confess
> I merely searched the doc rather than re-read it cover to cover.

I should have replied to this...

I don't think I've ever searched, so it's quite possible it's just something
"everyone knows", except when they don't.  We should put something in
the parameter expansion section in any case.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-08-06 16:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-07 17:37 On "the usual behaviour" of empty array elements Bart Schaefer
2012-08-05  7:09 ` Nikolai Weibull
2012-08-06 16:04 ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).