zsh-users
 help / color / mirror / code / Atom feed
* Array as parameter
@ 2011-11-02  3:35 meino.cramer
  2011-11-02  5:00 ` Wayne Davison
  0 siblings, 1 reply; 2+ messages in thread
From: meino.cramer @ 2011-11-02  3:35 UTC (permalink / raw)
  To: zsh-users

Hi,

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 

when executed shoult print
1
---
2
---
3
---
4
---
5
---
6
---


Thank you very mich in advance for any help!
Best regards,
mcc



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Array as parameter
  2011-11-02  3:35 Array as parameter meino.cramer
@ 2011-11-02  5:00 ` Wayne Davison
  0 siblings, 0 replies; 2+ messages in thread
From: Wayne Davison @ 2011-11-02  5:00 UTC (permalink / raw)
  To: meino.cramer; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 519 bytes --]

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) and then use "for i in
$*" in your function.  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.  With that one change, your function would work.

..wayne..

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-11-02  5:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-02  3:35 Array as parameter meino.cramer
2011-11-02  5:00 ` Wayne Davison

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