I have this current function used to create an array in a menu style (associative arrays can't be used in the scenario).
declare -a array1=("host1" "host2" "host3")
declare -a array2=("ip1" "ip2" "ip3")
function menusetup {
iter=0
for ((i=0; i<(count*2); i+=2)); do
menu[$i]=${array1[$iter]}
menu[$i+1]=${array2[$iter]}
((iter++))
done
}
menusetup
which gives me the menu array with {"host1" "ip1" "host2" "ip2" "host3" "ip3"
This is working perfect for what I needed, but now I want to reuse this function to pass any 2 arrays, something like this.
function menusetup {
iter=0
for ((i=0; i<(count*2); i+=2)); do
menu[$i]=${$1[$iter]}
menu[$i+1]=${$2[$iter]}
((iter++))
done
}
menusetup "${array3[@]}" "${array4[@]}"
Edit: I know the second example passes the entire list of elements of the array. I want to know if there is a way to pass and substitute the array