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

Re: double quoted expansion question



Am 07.09.2012 um 16:41 schrieb Bart Schaefer:

> 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}//* /}}}"

Wow, thanks. My mistake is that I thought that because the quotes are at the outermost level, the double quoted joining was not part of this and applied at the very end. This explains why my assumption was wrong for that case. For here-docs there seems to be yet another twist:

❯ cat <<EOF
${(s:,:uo)${(j:,:)${(@)${(f)servers}/* /}}} 
EOF
linux,gpu,users,linux,gpu,users,linux,mail,smtp,linux,users,linux,web,external,

❯ cat <<EOF
${(s:,:uo)${(j:,:)${${(f)servers}/* /}}}   
EOF
<empty line>


Sebastian



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