From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5253 invoked by alias); 3 Jul 2014 09:22:15 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32831 Received: (qmail 3920 invoked from network); 3 Jul 2014 09:22:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7f626d000004b39-8e-53b51e62d2be Date: Thu, 03 Jul 2014 10:12:01 +0100 From: Peter Stephenson To: Dima Kogan , zsh-workers Subject: Re: Odd expansion behavior Message-id: <20140703101201.5eaa57a4@pwslap01u.europe.root.pri> In-reply-to: <87pphm51lw.fsf@secretsauce.net> References: <87pphm51lw.fsf@secretsauce.net> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGLMWRmVeSWpSXmKPExsVy+t/xq7pJcluDDTreKFrM2XiQ1eJg80Mm ByaPWR3XWD1WHfzAFMAUxWWTkpqTWZZapG+XwJWx4MoSxoIG7oq9l48wNjAe4+hi5OSQEDCR 6F3VxQJhi0lcuLeerYuRi0NIYCmjxKUP9xkhnH4miV0tl9lBqlgEVCWmP1jFCmKzCRhKTN00 mxHEFhHwkLi79z9YjbCAssSNmw+BpnJw8ArYS/QvqAYJcwroShyYvBmsREhAR+Lv/bNgi/kF 9CWu/v3EBHGEvcTMK2fARvIKCEr8mHwPrIZZQEti87YmVghbXmLzmrfMExgFZiEpm4WkbBaS sgWMzKsYRVNLkwuKk9JzjfSKE3OLS/PS9ZLzczcxQsLy6w7GpcesDjEKcDAq8fC+0N8ULMSa WFZcmXuIUYKDWUmEd/rmLcFCvCmJlVWpRfnxRaU5qcWHGJk4OKUaGJ20mfrFlp58cD/8z1PW h5tKA62WPJud7DSb28fMZ1q3UFg7p7jqqbz4HcpGXAlrd6ZHn5C08oqbnxf8+Hj2r8RvzZXf WhjMDkVq3kit3qr23PRo7blUQ2VfHlbNtfdXLOk6fbTjdNY+NrWfnYl7zk0wz7ysdq5tp69R I096ztWEOa/3yd3OVmIpzkg01GIuKk4EACOu4dMpAgAA On Thu, 03 Jul 2014 00:43:23 -0700 Dima Kogan 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