title: Array intersection in Bash
body: <p>How do you compare two arrays in Bash to find all intersecting values?</p>
  <p>Let's say: <br />
  array1 contains values 1 and 2 <br />
  array2 contains values 2 and 3</p>
  <p>I should get back 2 as a result.</p>
  <p>My own answer:</p>
  <pre><code>for item1 in $array1; do
      for item2 in $array2; do
          if [[ $item1 = $item2 ]]; then
              result=$result&quot; &quot;$item1
          fi
      done
  done
  </code></pre>
  <p>I'm looking for alternate solutions as well.</p>