Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Array as parameter
- X-seq: zsh-workers 29884
- From: Stephane CHAZELAS <stephane_chazelas@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Array as parameter
- Date: Wed, 2 Nov 2011 09:04:49 +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__714.249446946447$1320205564$gmane$org@solfire>
2011-11-2, 04:35(+01), meino.cramer@xxxxxx:
> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author