From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 433 invoked from network); 14 Sep 2000 04:58:32 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 14 Sep 2000 04:58:32 -0000 Received: (qmail 4097 invoked by alias); 14 Sep 2000 04:57:57 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 12801 Received: (qmail 4090 invoked from network); 14 Sep 2000 04:57:56 -0000 From: "Bart Schaefer" Message-Id: <1000914045742.ZM7044@candle.brasslantern.com> Date: Thu, 14 Sep 2000 04:57:42 +0000 In-Reply-To: <200009131844.OAA01710@soup.ads.apexinc.com> Comments: In reply to "E. Jay Berkenbilt" "3.1.9-dev-6: bug or confusion?" (Sep 13, 2:44pm) References: <200009131844.OAA01710@soup.ads.apexinc.com> X-Mailer: Z-Mail (5.0.0 30July97) To: "E. Jay Berkenbilt" , zsh-workers@sunsite.auc.dk Subject: Re: 3.1.9-dev-6: bug or confusion? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Sep 13, 2:44pm, E. Jay Berkenbilt wrote: } Subject: 3.1.9-dev-6: bug or confusion? } } Define these two functions: } } function okay } { } emulate -L zsh } echo ${#${@:#-}} } setopt localoptions xtrace } (( ${#${@:#-}} )) } } } } function broken } { } emulate -L zsh } echo ${#${@#-}} } setopt localoptions xtrace } (( ${#${@#-}} )) } } } } zsh% broken - } 0 } +broken:5> (( 1 )) } } Why would the value be 1 inside (( ... )) and 0 outside in the second } case but not in the first? Does it have something to do with an empty } string being counted as a word in one case but not the other? Yes, it has something to do with that. (( stuff )) is equivalent to let "stuff" (note the double quotes). So the two expansions in `broken' should be akin to the difference between $@ (without quotes) and "$@". Where it gets confusing is that, in the nested expansion ${#${@}}, you first have the expansion of the inner $@, which (when not in quotes) implies that the empty elements disappear, and then the count is done on the remaining array. This is not the same as ${#@}, which counts the array *before* expanding it (see below). Aside to EJR: I should have remembered this. Finally, in ${@#-}, the pattern match/delete on each word is performed *before* the expansion, so again the resulting empty elements (if any) disappear only when the whole expression is not in quotes. Aside: This particular item is missing from the 11 "Rules" of parameter expansion in the Expansion chapter of the zsh manual. It happens after step 7, at approximately the same time as step 8 (because empty elements resulting from an (s) modifier are completely removed, even in quotes, but separators inserted by (j) are always added between the empties). Also missing is an exact indication of when ${^...} ${#...} and ${~...} are applied; ${#...} actually happens between steps 6 and 7, whereas the other two don't happen until after step 8. (Care to fix this up in a more accurate way in the docs, Peter?) The definition of ${...:#...} says explicitly that matched elements are completely removed from the array, so that's why there's no difference in the `okay' case. (And that happens at step 6, before (j).) -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net