title: Bash function with an array input and output
body: <p>If I define an array in bash shell:</p>
  
  <pre><code>a=()
  a+=("A")
  a+=("B")
  a+=("C")
  </code></pre>
  
  <p>I can interact with it as expected:</p>
  
  <pre><code>echo "${a[0]}"
  # Returns "A"
  
  echo "${a[1]}"
  # Returns "B"
  </code></pre>
  
  <p>But when I run that same array through a function, I must be do something wrong. First, I'll define my function:</p>
  
  <pre><code>function sort_array {
    declare -a array=("${!1}")
    local sorted=()
  
    sorted+=("1")
    sorted+=("2")
    sorted+=("3")
  
    echo "${sorted[@]}"
  }
  </code></pre>
  
  <p>Now let's call it and inspect the results:</p>
  
  <pre><code>b=()
  b=$(sort_array a[@])
  echo "${b[0]}"
  
  # Returns "1 2 3"
  # But I'm expecting b[0] == 1
  </code></pre>
  
  <p>What am I doing wrong? I realize my example could remove the function parameter entirely, but my end goal is to write a bash <code>sort_array()</code> function that I can pass an array to and get an array back for.</p>