title: Bash - How to pass array to function, with index defined in new function
body: <p>I have this current function used to create an array in a menu style (associative arrays can't be used in the scenario).</p>
  
  <pre><code>declare -a array1=("host1" "host2" "host3")
  declare -a array2=("ip1" "ip2" "ip3")
  
  function menusetup {
  
    iter=0
    for ((i=0; i&lt;(count*2); i+=2)); do
      menu[$i]=${array1[$iter]}
      menu[$i+1]=${array2[$iter]}
      ((iter++))
    done
  }
  
  menusetup
  </code></pre>
  
  <p>which gives me the menu array with <code>{"host1" "ip1" "host2" "ip2" "host3" "ip3"</code>
  This is working perfect for what I needed, but now I want to reuse this function to pass any 2 arrays, something like this.</p>
  
  <pre><code>function menusetup {
  
    iter=0
    for ((i=0; i&lt;(count*2); i+=2)); do
      menu[$i]=${$1[$iter]}
      menu[$i+1]=${$2[$iter]}
      ((iter++))
    done
  }
  
  menusetup "${array3[@]}" "${array4[@]}"
  </code></pre>
  
  <p>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</p>