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

Re: surprise with echo



On Dec 18, 2014, at 10:06 PM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:

> On Dec 18,  5:24pm, Ray Andrews wrote:
> 
> } Can that be prevented?
> 
> Only by turning off the option, or by doing e.g. ${@:-''} so that the
> expansion is the empty string rather than the empty array.

Also note that "preventing" it would amount to treating an empty array
the same as an array containing a single null value, which is currently
not the case:

    % emulate zsh && setopt RC_EXPAND_PARAM
    % foo=()
    % echo "abc${foo[*]}def"
    abcdef
    % echo "abc${foo[@]}def"

    % foo=('')
    % echo "abc${foo[*]}def"
    abcdef
    % echo "abc${foo[@]}def"
    abcdef

You're making quite a few assumptions about how positional parameters
and array substitution work. For instance, the fact that you're using
double quotes (which affects the expansion of $foo[*] versus $foo[@]) is
clouding your understanding of how RC_EXPAND_PARAM works. Observe:

    % emulate zsh && setopt RC_EXPAND_PARAM
    % foo=()
    % echo "abc${foo[*]}def"
    abcdef
    % echo abc${foo[*]}def

    %

Please read zshparam(1).

vq


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