zsh-workers
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <vq@larryv.me>
To: zsh-workers@zsh.org
Subject: ${#${(A)=name=word}} behavior depends on number of elements
Date: Fri, 12 Aug 2016 18:11:47 -0400	[thread overview]
Message-ID: <DC080C9F-3A3D-4B68-BE29-765F7898647F@larryv.me> (raw)

As I would expect, ${#${(A)=name=word}} expands to the number of
elements in array "foo" after assignment.

	% unset foo; echo ${#${(A)=foo=a 'b c' d}}; typeset foo
	3
	foo=( a 'b c' d )

However, if "foo" ends up with just one element, the expression expands
to the number of characters in that element.

	% unset foo; echo ${#${(A)foo=abc}}; typeset foo    
	3
	foo=( abc )
	% unset foo; echo ${#${(A)=foo=abc}}; typeset foo 
	3
	foo=( abc )
	% unset foo; echo ${#${(A)foo=a b c}}; typeset foo  
	5
	foo=( 'a b c' )
	% unset foo; echo ${#${(A)=foo='a b c'}}; typeset foo
	5
	foo=( 'a b c' )

The behavior is the same for ":=" and "::=".

	% echo $ZSH_PATCHLEVEL
	zsh-5.2-0-gc86c20a
	% setopt
	combiningchars
	extendedhistory
	incappendhistorytime
	interactive
	login
	monitor
	promptsubst
	shinstdin
	zle

vq


             reply	other threads:[~2016-08-12 22:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-12 22:11 Lawrence Velázquez [this message]
2016-08-12 23:04 ` 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=DC080C9F-3A3D-4B68-BE29-765F7898647F@larryv.me \
    --to=vq@larryv.me \
    --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).