zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane CHAZELAS <stephane_chazelas@yahoo.fr>
To: zsh-workers@zsh.org
Subject: Re: Array as parameter
Date: Wed, 2 Nov 2011 09:10:46 +0000 (UTC)	[thread overview]
Message-ID: <slrnjb228m.67l.stephane.chazelas@spam.is.invalid> (raw)
In-Reply-To: <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@gmx.de> 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


       reply	other threads:[~2011-11-02  9:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20111102033545.GI28043@solfire>
     [not found] ` <CAHSx_SsGPHWkGfspXKo39oZ6G3Rd+H-8_2PAuixHmW94d4VCEg__34702.1825182766$1320210589$gmane$org@mail.gmail.com>
2011-11-02  9:10   ` Stephane CHAZELAS [this message]
2011-11-02 10:14     ` Mikael Magnusson
2011-11-02 12:06       ` Stephane Chazelas
2011-11-02 12:13         ` Mikael Magnusson
2011-11-02 12:15           ` Mikael Magnusson
     [not found] <20111102033545.GI28043__714.249446946447$1320205564$gmane$org@solfire>
2011-11-02  9:04 ` Stephane CHAZELAS

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=slrnjb228m.67l.stephane.chazelas@spam.is.invalid \
    --to=stephane_chazelas@yahoo.fr \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).