Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
${#${(A)=name=word}} behavior depends on number of elements
- X-seq: zsh-workers 39034
- From: Lawrence Velázquez <vq@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: ${#${(A)=name=word}} behavior depends on number of elements
- Date: Fri, 12 Aug 2016 18:11:47 -0400
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=larryv.me; h= content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=rtH eTFSAIhAZtj3bdymlp4F7Lec=; b=duZ/e/9nh4hwuaPDUF8zoFkffkPNxbqKzSc leZusb68OsjTCbH5HDCcMnWW60EcPiqGWVLUcK/hjC547Hqm3HjvNkYZm0jzqWKl Mt6uDheMfKGd1zZQkN36wi+c04MJzor5SZcUXPM+u2UmaRINpfh24h8A4aa2zPId g0acSxQ4=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=rtHeTFSAIhAZtj3bdymlp4F7Lec=; b=R4V9c JebuqZ5fmYrCmQeQt1dvq5mGOvppxzAv0Wd44zOyxg2g9BcWqTYVO9NRCf0N4WSv rR4KH1zRhQcdKRuSt7ZnQM/bc6nxZN8X0YhXeXzFWCtZWjvVlz60H9Z115B42sdM OGyL2GUewO1sADa0KlgGfwZ85NkTTnIjHD+Nec=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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