title: Merging two arrays in Bash
body: <p>I have two arrays <code>A</code> and <code>B</code>. I want to combine them into a new array <code>C</code>, which is their Cartesian product:</p>
  <pre><code>A=( 0 1 )
  B=( 1 2 )
  
  # Desired output:
  C=( 0:1 0:2 1:1 1:2 )
  </code></pre>
  <p>I tried:</p>
  <pre><code>   for ((z = 0; z &lt;= ${#A[@]}; z++)); do
       for ((y = 0; y &lt;= ${#B[@]}; y++)); do
         C[$y + $z]=&quot;${A[$z]}:&quot;
         C[$y + $z + 1]=&quot;${B[$y]}&quot;
       done
     done
  </code></pre>
  <p>But that outputs:</p>
  <pre><code> 0: : : :
  </code></pre>
  <p>I expected <code>0:1 0:2</code> for <code>A = ( 0 )</code> and <code>B = ( 1 2 )</code>.</p>