zsh-users
 help / color / mirror / code / Atom feed
* Weird rc_expand_param side effect or whitespace splitting
@ 2023-02-14 20:17 Philippe Troin
  2023-02-14 21:11 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Troin @ 2023-02-14 20:17 UTC (permalink / raw)
  To: zsh-users

This has been stumping me:

   #!/bin/zsh -f
   
   echo $ZSH_VERSION 
   
   x=$'\t\t\t'
   
   y=("${(ps:\t:)x}")
   echo $#y
   
   setopt rcexpandparam
   y=("${(ps:\t:)x}")
   echo $#y

This script prints:
   5.8.1
   2
   4

Why does rc_expand_param interacts with string splitting?

I know that if you use:

   y=("{(@ps:\t:)x}")

Then $#y is always 4, whatever rcexpandparams is set to.

Phil.


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

* Re: Weird rc_expand_param side effect or whitespace splitting
  2023-02-14 20:17 Weird rc_expand_param side effect or whitespace splitting Philippe Troin
@ 2023-02-14 21:11 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2023-02-14 21:11 UTC (permalink / raw)
  To: Philippe Troin; +Cc: zsh-users

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.


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

end of thread, other threads:[~2023-02-14 21:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 20:17 Weird rc_expand_param side effect or whitespace splitting Philippe Troin
2023-02-14 21:11 ` Bart Schaefer

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).