From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1933 invoked by alias); 2 Nov 2011 09:20:28 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29885 Received: (qmail 1887 invoked from network); 2 Nov 2011 09:20:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at m.gmane.org designates 80.91.229.12 as permitted sender) X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: zsh-workers@zsh.org To: zsh-workers@zsh.org From: Stephane CHAZELAS Subject: Re: Array as parameter Date: Wed, 2 Nov 2011 09:10:46 +0000 (UTC) Message-ID: References: <20111102033545.GI28043@solfire> X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 188-223-3-27.zone14.bethere.co.uk Mail-Copies-To: nobody User-Agent: slrn/pre1.0.0-18 (Linux) 2011-11-1, 22:00(-07), Wayne Davison: > --000e0cd299861c09c804b0b95bb8 > Content-Type: text/plain; charset=UTF-8 > > On Tue, Nov 1, 2011 at 8:35 PM, wrote: > >> arrprint a >> > > That passes the string "a" to the function. One thing you can do is to > pass the array as separate parameters (arrprint $a) $a discards the empty elements in the "a" array. Use "${a[@]}" instead. > and then use "for i in > $*" in your function $* in zsh also discards the empty elements (it's even worse in compatibility mode with other shells where word splitting and filename generation may also be done). Use "$@" instead. Or better, write it "for i do". > However, if you need to be able to keep the array > parameter separate from other parameters, you could instead refer to the > variable whose name you passed in using ${(P)1} in your function in place > of the $1. Except that it doesn't work for arrays. You'd need to use eval here. -- Stephane