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

Re: double quoted expansion question



On Sep 7,  2:31pm, Sebastian Stark wrote:
}
} Dear zsh users,
} 
} What I would like to understand here is why the output changes the way
} it does when I add double quotes around my expression. I would expect
} the same output as without. If anybody could shed some light please, I
} guess it's just something obvious I cannot see.

It may help to read the "Rules" subsection in the "Parameter Expansion"
section of the zsh manual.

Note that "double quoted joining" happens at step 5, before "modifiers"
[including the //* / replacement] at step 7.  Although "forced splitting"
(the s and f flags) doesn't happen until step 16, "nested substitution"
happens at step 1, so your innermost ${(f)servers} still happens before
double quoted joining is done, and it's the result of that split that is
then joined on spaces, causing //* / to do something you don't expect.

So what you need to do is tell zsh not to join that array, which you do
by adding the @ flag at the nesting level where the join would happen:

    print "${(s:,:uo)${(j:,:)${(@)${(f)servers}//* /}}}"

Also note that "forced joining" (the j flag) is applied at step 5 when
the substitution is in double quotes, but not until step 10 when unquoted.
That matters here only to explain why you need only one @ flag.

BTW, you don't need // there; there is only one space in each array
element after ${(f)servers}, so ${(@)${(f)servers}/* /}} is enough.



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