From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 793 invoked from network); 7 Feb 2003 16:49:24 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 7 Feb 2003 16:49:24 -0000 Received: (qmail 19066 invoked by alias); 7 Feb 2003 16:48:56 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5890 Received: (qmail 19059 invoked from network); 7 Feb 2003 16:48:56 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 7 Feb 2003 16:48:56 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [4.46.181.248] by sunsite.dk (MessageWall 1.0.8) with SMTP; 7 Feb 2003 16:48:55 -0000 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id h17Gmvk25339 for zsh-users@sunsite.dk; Fri, 7 Feb 2003 08:48:57 -0800 From: "Bart Schaefer" Message-Id: <1030207164856.ZM25338@candle.brasslantern.com> Date: Fri, 7 Feb 2003 16:48:56 +0000 In-Reply-To: <12330.1044614892@csr.com> Comments: In reply to Peter Stephenson "Re: set -A" (Feb 7, 10:48am) References: <12330.1044614892@csr.com> X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-users@sunsite.dk Subject: Re: set -A MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Feb 7, 10:48am, Peter Stephenson wrote: } } "Bart Schaefer" wrote: } > If you've unset arr, then arr is not an array, and hence ${arr[@]} is } > not an array either, and therefore "${arr[@]}" does not behave like } > an array; rather, it behaves like a string, so putting it in double } > quotes yields the empty string. } } But the `@' subscript is not documented to do anything useful for } strings That's not strictly true. The docs say, in consecutive paragraphs: ---------- A subscript of the form `[*]' or `[@]' evaluates to all elements of an array; there is no difference between the two except when they appear within double quotes. [...] Subscripting may also be performed on non-array values, in which case the subscripts specify a substring to be extracted. ---------- } nor can I see why anyone would assume it was useful in that case It does NOT say that subscripting non-array values is limited to using integer ranges; it just says "subscripting may also be performed." } nor, if they *did* think, that why they would assume that it } produced a null string instead of the usual elision of the argument. } (I haven't put that very well.) You put it well enough, and that last is a valid point. Since for foo=(x y z) we have "$foo[@]" equivalent to "x" "y" "z", then given foo=xyz, should the expectation be that "$foo[@]" is "x""y""z" ? (Note no word breaks between the quoted substrings.) That might have some pretty bizarre side-effects for nested expansions. } I think we could safely and consistently have a non-existent parameter } treated as an array in this special case without any negative impact. It's actually worse than that, though, because ksh treats ALL parameters as arrays -- in ksh, foo=xyz is the same as foo=(xyz) in zsh, and the fiction of string variables is maintained by making $foo a reference to ${foo[0]}. So when KSH_ARRAYS is set, ${foo[1]} (or any number greater than zero) ought to produce an empty result when used on a scalar.