title: Find words in common between two strings faster than nested-for-loop approach in bash
body: <p>Suppose I have a the following:</p>
  
  <pre><code>a="one two three four"
  b="four five two six"
  </code></pre>
  
  <p>I want to find words in common between the two strings with a mechanism faster than the naive <code>for</code> loop approach given below.</p>
  
  <pre><code># This gives the result I want, but is too slow.
  for word in ${a[@]}; do
      if [[ "$b" == *"$word "* ]]; then
          matching_word="$word"
          echo $word
      fi
  done
  </code></pre>
  
  <p>but I've found for my purposes a for loop is really slowing me down because it gets run very frequently. I'm not sure if there's a good alternative this. </p>