Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: passing arrays



Le Wang wrote:
>Is it possible to pass an array into a function and
>have the function return an array?

The arguments to a function are an array, accessible through the
$1/$@/$argv parameters.

A function directly returns only a numeric status.  To return any
other information, it must either assign to a parameter or generate
output (which can be captured using $(...)).  The parameter assignment
technique is usually to be preferred, because it doesn't need to make any
system calls and it's easier for handling arrays.  We already have some
mechanisms where the shell calls a user-defined function and receives
a string or array return code in the parameters $REPLY or $reply;
I suggest that where you need string or array returns you use these
parameter names to do it.

-zefram



Messages sorted by: Reverse Date, Date, Thread, Author