bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: passing arrays as parameters to functions


From: Mike Frysinger
Subject: Re: passing arrays as parameters to functions
Date: Sat, 18 Apr 2009 14:26:38 -0400
User-agent: KMail/1.11.1 (Linux/2.6.28; KDE/4.2.1; x86_64; ; )

On Friday 17 April 2009 12:29:29 sharkura wrote:
> I am looking for a way to pass an array variable as an argument to a
> function.  The only remotely similar post I found dealt with spaces in
> arguments, which is not my problem.
>
> I want to pass three arguments to a function.  I want to receive them as
> three positional parameters, $1 (an array), $2 (a scalar integer), and $3
> (another scalar integer).  The integers are optional.
>
> Currently, if I pass my array argument as ${arrayArg[@]}, the contents
> actually expand to positional parameters $1, $2, ... $N.  I could just
> assume that the last two positional parameters are my two integer
> arguments, but I'd like them to be optional.  The size of the array is not
> fixed.
>
> I've googled and searched this forum, but all the examples I've found use a
> global array that is not passed as an argument, but defined prior to the
> function that uses it.   Kind of ugly to me, but a solution if no other
> exists.

other options:
 - rebuild array using $@
 - pass var by reference and duplicate it manually in the function:
        do_something arrayArg

otherwise, what you mention is best i could think of real quick ...
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]