zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: $^=var and leading/trailing blanks
Date: Mon, 10 Oct 2016 20:18:36 -0700	[thread overview]
Message-ID: <CAH+w=7YSZVmOjFjkY=EqX7eS9j3GDXMmoonPJ0SD+5XxvRVO2A@mail.gmail.com> (raw)
In-Reply-To: <20161008151244.GA7037@chaz.gmail.com>

On Sat, Oct 8, 2016 at 8:12 AM, Stephane Chazelas
<stephane.chazelas@gmail.com> wrote:
>
> Why the extra first and last element the the first two commands?

This is sort of explained under the s:: expansion flag:

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

          line="one::three"
          print -l "${(s.:.)line}"

     produces two lines of output for one and three and elides the
     empty field.  To override this behaviour, supply the "(@)" flag as
     well, i.e.  "${(@s.:.)line}".

When you add the rcexpandparam flag, you get "the usual behavior" back
again (otherwise an array of only empty elements would behave like an
empty array and discard everything).  When you  nest the expansions,
the inner split gets the empty elements removed when it expands, and
then rcexpandparam applies to the remaining elements of that result.

You don't get two elements for the two leading spaces because
shwordsplit behaves that way.  If you use (s: :) instead, then you do
get one empty element for each space.


      reply	other threads:[~2016-10-11  4:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-08 15:12 Stephane Chazelas
2016-10-11  3:18 ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7YSZVmOjFjkY=EqX7eS9j3GDXMmoonPJ0SD+5XxvRVO2A@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).