From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10324 invoked from network); 10 Oct 2003 20:15:35 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 10 Oct 2003 20:15:35 -0000 Received: (qmail 16768 invoked by alias); 10 Oct 2003 20:15:16 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19181 Received: (qmail 16737 invoked from network); 10 Oct 2003 20:15:16 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 10 Oct 2003 20:15:16 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [195.92.193.21] by sunsite.dk (MessageWall 1.0.8) with SMTP; 10 Oct 2003 20:15:15 -0000 Received: from modem-147.michigan.dialup.pol.co.uk ([62.137.73.147] helo=pwstephenson.fsnet.co.uk) by cmailm5.svr.pol.co.uk with esmtp (Exim 4.14) id 1A83fO-0002oL-Rn; Fri, 10 Oct 2003 21:15:15 +0100 Received: by pwstephenson.fsnet.co.uk (Postfix, from userid 501) id 0441A84E0; Fri, 10 Oct 2003 16:16:58 -0400 (EDT) Received: from pwstephenson.fsnet.co.uk (localhost [127.0.0.1]) by pwstephenson.fsnet.co.uk (Postfix) with ESMTP id C8B6184C7; Fri, 10 Oct 2003 21:16:58 +0100 (BST) To: Stephane Chazelas Cc: Zsh hackers list Subject: Re: array expansion (Was: [bug-report] brace_ccl and $'\0' in ranges) In-reply-to: "Stephane Chazelas"'s message of "Tue, 07 Oct 2003 10:14:17 +0200." <20031007081417.GA418@pcchazelas.free.fr> Date: Fri, 10 Oct 2003 21:16:57 +0100 From: Peter Stephenson Message-Id: <20031010201658.0441A84E0@pwstephenson.fsnet.co.uk> Stephane Chazelas wrote: > I've tried subscribing my other address at yahoo.fr, let's see. Didn't seem to work. Here's what SpamAssassin says about your mail; it ends up with a sizeable negative score, so I doubt if this helps. X-Spam-Status: No, hits=-8.6 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, RCVD_IN_OSIRUSOFT_COM,REFERENCES,REPLY_WITH_QUOTES, USER_AGENT_MUTT autolearn=ham version=2.55 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) > What is the historical reason why > > array=(1 "" "3 4") > cmd $array > # is cmd 1 "3 4" > > the empty arguments are stripped. I suppose it's because the same thing happens with individual scalars. An array element basically behaves as a scalar. (This is similar to other shells.) > I understand that zsh arrays are not hashes as in ksh or bash, > and always start at index 1, even if you only define array[12], > but wasn't it simpler to have: > > array=(1 "" "3 4") > cmd $array > # is cmd 1 "" "3 4" > # and > cmd ${array:#} > # is cmd 1 "3 4" > > I more often need to use "${array[@]}" expansion, than the > $array one. > Note that the user guide is clear about this behavior, but not > the manual. It says: > > | A subscript of the form `[*]' or `[@]' evaluates to all elements > | of an array; [...] When an array parameter is referenced as > | `$NAME' (with no subscript) it evaluates to `$NAME[*]' > > no reference about the empty elements implicit filtering. > > Same thing for > var= > cmd $var > # turned into cmd > # instead of cmd "" > cmd ${var+$var} > # would have made it. > > I end up having to use "$var" and "${array[@]}" everywhere as in > other shells. Yes, that's the long and short of it, if you need to preserve empty array elements. -- Peter Stephenson Work: pws@csr.com Web: http://www.pwstephenson.fsnet.co.uk