On Fri, 17 Apr 2009, 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 ${arraya...@]}, 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.
func() { local f_array eval "f_array=( \"\${...@]}\" )" printf "%s\n" "${f_arr...@]}" } a=( qw er ty ui op ) func a -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com> =================================================================== Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)