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

Re: quoting curiosity



On Sat, Nov 7, 2026 at 6:56 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
>
> Doing some housekeeping in a utility of mine, and knowing that quotation is usually best -- besides it sets the color coding in my editor the way I like it -- I changed this:
>
> set -A "${IN[mouse_clicks]}" $Mclicks
>
> ... to this:
>
> set -A "${IN[mouse_clicks]}" "$Mclicks"
>
> ... and it broke the function.  Why would that be?  I haven't done any forensics on it at all, because maybe there's some simple, obvious reason.

% a=(1 2 3)
% print -l $a
1
2
3
% print -l "$a"
1 2 3

based on the -A in your `set -A`, i would assume that Mclicks is in
fact an array?
If you really want the quotes, you can use
% print -l "${(@)a}"
1
2
3

or
% print -l "$a[@]"
1
2
3

(the latter variant obviously only works if you want all members of
the array, while the former lets you write "${(@)a[1,3]}" or
whatever).

Long story short, unless you want to protect empty elements from being
elided, { eg if a=( 1 '' 3 ), then unquoted $a will expand to 1 and 3
(as separate elements), while "$a[@]" will expand to three elements
with the middle one being the empty string }, then just don't put the
quotes, in my opinion. Note that in neither case are spaces in element
values an issue, unless you have done setopt shwordsplit which would
be silly to do.

-- 
Mikael Magnusson




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