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

${#${(A)=name=word}} behavior depends on number of elements



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



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