title: Finding presence of substring within a string in BASH
body: <p>I have a script that is trying to find the presence of a given string inside a file of arbitrary text.</p>
  <p>I've settled on something like:</p>
  <pre><code>#!/bin/bash
  file=&quot;myfile.txt&quot;
  for j in `cat blacklist.txt`; do
    echo Searching for $j...
    unset match
    match=`grep -i -m1 -o &quot;$j&quot; $file`
    if [ $match ]; then
      echo &quot;Match: $match&quot;
   fi
  done
  </code></pre>
  <p>Blacklist.txt contains lines of potential matches, like so:</p>
  <pre><code>matchthis
  &quot;match this too&quot;
  thisisasingleword
  &quot;This is multiple words&quot;
  </code></pre>
  <p>myfile.txt could be something like:</p>
  <pre><code>I would matchthis if I could match things with grep.  I really wish I could. 
  When I ask it to match this too, it fails to matchthis.  It should match this too - right?
  </code></pre>
  <p>If I run this at a bash prompt, like so:</p>
  <pre><code>j=&quot;match this too&quot;
  grep -i -m1 -o &quot;$j&quot; myfile.txt
  </code></pre>
  <p>...I get &quot;match this too&quot;.</p>
  <p>However, when the batch file runs, despite the variables being set correctly (verified via echo lines), it never greps properly and returns nothing.</p>
  <p>Where am I going wrong?</p>