I have this array:
PARAMETERS_OF_COMPONENTS[1]="component1"
PARAMETERS_OF_COMPONENTS[2]="component21 component22 component23"
PARAMETERS_OF_COMPONENTS[3]="component3"
PARAMETERS_OF_COMPONENTS[4]="component41 component42 component43"
I want to pass that array to this function:
foo()
{
local param1="$1"
local param2="$2"
local array_param="$3"
. . .
echo "${PARAMETERS_OF_COMPONENTS[@]}"
}
When I pass an array in this manner:
foo "$param1" "$param2" "${PARAMETER_OF_COMPONENTS[@]}"
then function just prints:
component1
Also, I've been tried couple of other methods to pass array, but I still didn't find right solution.
How can I pass correctly array to function? Also, solution must be compatible with Dash (at least without bashisms).
UPD @Kusalananda explained to me that Dash doesn't support an arrays. Thank's for clarify.
I will ask another one. How can I pass many parameters to function without pass it directly in manner $1
,$2
... and don't involve global variables? I have several ideas, but I would to listen yours approaches?
My task is to move function from one file to another, but that function uses global variables. I don't want to use global variables. So how to do this in the most right way?