zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Stark <seb@biskalar.de>
To: zsh-users@zsh.org
Subject: Re: double quoted expansion question
Date: Fri, 7 Sep 2012 17:43:19 +0200	[thread overview]
Message-ID: <FDDD2573-9AF3-413D-A4BD-6AEC681A0B69@biskalar.de> (raw)
In-Reply-To: <29236168-55B5-4555-9ACA-B1D21D345EA9@biskalar.de>


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


  parent reply	other threads:[~2012-09-07 15:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-07 12:31 Sebastian Stark
2012-09-07 12:47 ` Jérémie Roquet
2012-09-07 12:54   ` Jérémie Roquet
2012-09-07 14:36     ` Sebastian Stark
2012-09-07 14:41 ` Bart Schaefer
2012-09-07 15:43 ` Sebastian Stark [this message]
2012-09-08  5:38   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=FDDD2573-9AF3-413D-A4BD-6AEC681A0B69@biskalar.de \
    --to=seb@biskalar.de \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).