Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Array as parameter
- X-seq: zsh-workers 29885
- From: Stephane CHAZELAS <stephane_chazelas@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Array as parameter
- Date: Wed, 2 Nov 2011 09:10:46 +0000 (UTC)
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mail-copies-to: nobody
- Mail-followup-to: zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20111102033545.GI28043@solfire> <CAHSx_SsGPHWkGfspXKo39oZ6G3Rd+H-8_2PAuixHmW94d4VCEg__34702.1825182766$1320210589$gmane$org@mail.gmail.com>
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, <meino.cramer@xxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author