title: bash/shell pass array to function then loop?
body: <p>When defining an Array directly in the function the below works as expected;</p>
  
  <pre><code>function each {
    local array=(1 2 3)
    len=${#array[*]}
    for (( i=0; i&lt;len; i++ )); do
      echo ${array[$i]}
    done
  }
  
  each
  
  # outputs;
  
  1
  2
  3
  </code></pre>
  
  <p>But I can't figure out how to pass the array in as an argument and achieve the same output;</p>
  
  <pre><code>function each {
    local array=$1
    len=${#array[*]}
    for (( i=0; i&lt;len; i++ )); do
      echo ${array[$i]}
    done
  }
  
  array=(1 2 3)
  each array
  
  # outputs;
  
  array
  </code></pre>
  
  <p>Grateful for any help, thanks.</p>