zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Philippe Troin <phil@fifi.org>
Cc: zsh-users@zsh.org
Subject: Re: Weird rc_expand_param side effect or whitespace splitting
Date: Tue, 14 Feb 2023 13:11:08 -0800	[thread overview]
Message-ID: <CAH+w=7bCQbt-qSg6XpsuMnBs8LE4GooO+C2ZL-avmXn0zuD3Kw@mail.gmail.com> (raw)
In-Reply-To: <5af9ede7d352f5f35d051cfa7df904994575bfc3.camel@fifi.org>

On Tue, Feb 14, 2023 at 12:17 PM Philippe Troin <phil@fifi.org> wrote:
>
> Why does rc_expand_param interacts with string splitting?

Because it causes the empty results in the middle not to be dropped.

% unsetopt rcexpandparam
   y=("1${(ps:\t:)x}2")
   printf "<%s>\n" "$y[@]"
<1>
<2>
% setopt rcexpandparam
   y=("1${(ps:\t:)x}2")
   printf "<%s>\n" "$y[@]"
<12>
<12>
<12>
<12>

> I know that if you use:
>
>    y=("{(@ps:\t:)x}")
>
> Then $#y is always 4, whatever rcexpandparams is set to.

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

rcexpandparam wouldn't work properly if that applied when it is set.

The admonition under RC_EXPAND_PARAM ...
     ...  Note that an empty array
     will therefore cause all arguments to be removed.

... doesn't apply inside double-quotes because there an empty array
expands to an empty string rather than to an empty array element.


      reply	other threads:[~2023-02-14 21:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14 20:17 Philippe Troin
2023-02-14 21:11 ` 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=7bCQbt-qSg6XpsuMnBs8LE4GooO+C2ZL-avmXn0zuD3Kw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=phil@fifi.org \
    --cc=zsh-users@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).