zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Dima Kogan <dima@secretsauce.net>, zsh-workers <zsh-workers@zsh.org>
Subject: Re: Odd expansion behavior
Date: Thu, 03 Jul 2014 10:12:01 +0100	[thread overview]
Message-ID: <20140703101201.5eaa57a4@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <87pphm51lw.fsf@secretsauce.net>

On Thu, 03 Jul 2014 00:43:23 -0700
Dima Kogan <dima@secretsauce.net> wrote:
> I'm observing something odd. It might be a bug, but I don't understand
> it well-enough to call it that.
> 
> I see this:
> 
> $ x=(1 2 3); echo xxx${^x}
> xxx1 xxx2 xxx3
> 
> This output makes sense. However something slightly different is strange:
> 
> $ x=(1 2 3); y=xxx${^x}; echo $y
> xxx1 2 3
> 
> I asked on #zsh and osse helpfully pointed out that this can be made to
> work by expressing the assignment as 'y=(xxx${^x})' instead, which does
> work.

That's the difference between a scalar and an array assignment.  In a
scalar assignment, arrays are forced immediately to scalars, i.e. single
strings joined (by default) with spaces.  So the $x gets turned
immediately into "1 2 3"; the "^" has no special effect because you're
just joining that string with the "xxx".

It's a little bit like (but not exactly the same as) putting double
quotes around the expression.

It might throw a little bit of extra light on this if you look at the
words that are coming out; you can do this with "print -l" which outputs
one word per line.  So in the first case and after array assignment you
get

xxx1
xxx2
xxx3

because you are getting three different words from ${^x}, each one
joined to xxx, while after the scalar expansion you get

xxx1 2 3

because you have a single word.

pws


  reply	other threads:[~2014-07-03  9:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-03  7:43 Dima Kogan
2014-07-03  9:12 ` Peter Stephenson [this message]
2014-07-03 12:28   ` Peter Stephenson

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=20140703101201.5eaa57a4@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=dima@secretsauce.net \
    --cc=zsh-workers@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).