<p>I have a string in Bash:</p>
<pre class="lang-sh prettyprint-override"><code>string=&quot;My string&quot;
</code></pre>
<p>How can I test if it contains another string?</p>
<pre class="lang-sh prettyprint-override"><code>if [ $string ?? 'foo' ]; then
  echo &quot;It's there!&quot;
fi
</code></pre>
<p>Where <code>??</code> is my unknown operator. Do I use <code>echo</code> and <code>grep</code>?</p>
<pre class="lang-sh prettyprint-override"><code>if echo &quot;$string&quot; | grep 'foo'; then
  echo &quot;It's there!&quot;
fi
</code></pre>
<p>That looks a bit clumsy.</p>

I am not sure about using an if statement, but you can get a similar effect with a case statement:
```
```
case "$string" in 
  *foo*)
    # Do stuff
    ;;
esac
```
```