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

Re: nesting issue



On Sun, May 5, 2024, at 9:13 AM, Ray Andrews wrote:
> On 2024-05-04 20:20, Bart Schaefer wrote:
>> They give "bad substitution" because you can't have a space before the
>> closing "}" / after the closing ")" in the parameter expansion.
>> 
>> local sorted=( "${(f)$(print -l "${(n)in[@]}")}" )
>> 
> Nuts, I wouldn't have even considered that.   
>
> Even tho it is accepted here?:
>
>     sorted=( "${(f)sorted}" )

You're not comparing the right spaces.  The problem Bart pointed
out is more akin to

        sorted=( "${(f)sorted }" )


> One thing tho, since nested quotes end up un-quoting the inner 
> quotation (or is this an exception?)

Command substitution introduces a new quoting context.  Things like

        "$(cmd "arg with spaces")"

work fine.


> I'm thinking that:
>
>  local sorted=( "${(f)$(print -l ${(n)in[@]})}" )
>
> ... one set of quotes -- should be fine.  And it seems fine.

Unquoted ${(n)in[@]} drops empty elements and is equivalent to
unquoted ${(n)in}.  Whether that's acceptable is dependent on
application requirements, as always.


-- 
vq




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