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:04:49 +0000 (UTC)	[thread overview]
Message-ID: <slrnjb21th.67l.stephane.chazelas@spam.is.invalid> (raw)
In-Reply-To: <20111102033545.GI28043__714.249446946447$1320205564$gmane$org@solfire>

2011-11-2, 04:35(+01), meino.cramer@gmx.de:
> how can I use an array as a parameter to a function like
> this (example does not work...just as an explanation, what
> I want to do)
>
>     #! /bin/zsh
>     funcion arrprint()
>     {
>         for i in $1
>         do
>             echo $i
>             echo "---"
>         done
>     }
>
>     a=( 1 2 3 4 5 6 )
>
>     arrprint a 
[...]

Try (pass by values)

arrprint() {
  for i do
    echo "$i"
    echo ---
  done
}
arrprint "${a[@]}"

Or (pass by name)

arrprint() {
  eval 'set -- "${'$1'[@]}"'
  for i do
    echo "$i"
    echo ---
  done
}
arrprint a

-- 
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__714.249446946447$1320205564$gmane$org@solfire>
2011-11-02  9:04 ` Stephane CHAZELAS [this message]
     [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
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

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=slrnjb21th.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).