title: Is it possible to perform array assignment before a command in bash?
body: <p>I am experimenting with passing arrays to a shell script, as described in <a href="https://stackoverflow.com/questions/1063347/passing-arrays-as-parameters-in-bash/6828383#6828383">this question</a>. I wrote a little script that is simply designed to take in the name of an array and print out the array:</p>
  
  <pre><code>#!/bin/bash
  echo "$1"
  echo "${!1}"
  arrayVar=("${!1}")
  echo "${arrayVar[1]}"
  </code></pre>
  
  <p>I declare an array variable in line with running my script, like so:</p>
  
  <pre><code>array=(foo bar test) ./test.sh array[@]
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>|array[@]         # the bars are only here to force the final blank line
  |(foo bar test)
  |
  </code></pre>
  
  <p>It seems that <code>array</code>, instead of actually being an array, is simply the string <code>(foo bar test)</code></p>
  
  <p>Even if I modify my script to echo <code>array</code> directly by name instead of indirectly through the positional parameter, I get the same result.</p>
  
  <pre><code>#!/bin/bash
  echo "$1"
  arrayVar=("${!1}")
  echo $arrayVar
  echo "${arrayVar[1]}"
  
  echo $array
  echo "${array[1]}"
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>|array[@]         # the bars are only here to force the final blank line
  |(foo bar test)
  |
  |(foo bar test)
  |
  </code></pre>
  
  <p>Am I simply doing something wrong, or does bash not support array assignments before a command?</p>