As we know, in bash programming, the method of passing arguments is $1 , ..., $N However, I found that it is not easy to pass an array as an argument to a function that receives more than one argument. Here is one example:
f(){ x=($1) y=$2 for i in "${x[@]}" do echo $i done .... } a=("jfaldsj jflajds" "LAST") b=NOEFLDJF f "${a[@]}" $b f "${a[*]}" $b
As described, the function f receives two arguments: the first is assigned x which is an array, the second - y .
f can be called in two ways. The first method uses "${a[@]}" as the first argument, and the result:
jfaldsj jflajds
The second method uses "${a[*]}" as the first argument, and the result:
jfaldsj jflajds LAST
None of the results match what you want. So, does anyone have any ideas on how to properly pass an array between functions?
arrays bash shell
Red Lv May 09 '13 at 12:20 2013-05-09 12:20
source share