title: How do I compare two string variables in an 'if' statement in Bash?
body: <p>I'm trying to get an <code>if</code> statement to work in <a href="http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29" rel="noreferrer">Bash</a> (using <a href="http://en.wikipedia.org/wiki/Ubuntu_%28operating_system%29" rel="noreferrer">Ubuntu</a>):</p>
  
  <pre><code>#!/bin/bash
  
  s1="hi"
  s2="hi"
  
  if ["$s1" == "$s2"]
  then
    echo match
  fi
  </code></pre>
  
  <p>I've tried various forms of the <code>if</code> statement, using <code>[["$s1" == "$s2"]]</code>, with and without quotes, using <code>=</code>, <code>==</code> and <code>-eq</code>, but I still get the following error:</p>
  
  <blockquote>
    <p>[hi: command not found</p>
  </blockquote>
  
  <p>I've looked at various sites and tutorials and copied those, but it doesn't work - what am I doing wrong?</p>
  
  <p>Eventually, I want to say if <code>$s1</code> contains <code>$s2</code>, so how can I do that?</p>
  
  <p>I did just work out the spaces bit... :/ How do I say <em>contains</em>?</p>
  
  <p>I tried</p>
  
  <pre><code>if [[ "$s1" == "*$s2*" ]]
  </code></pre>
  
  <p>but it didn't work.</p>