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

Re: Weird rc_expand_param side effect or whitespace splitting



On Tue, Feb 14, 2023 at 12:17 PM Philippe Troin <phil@xxxxxxxx> 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.




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