title: "[ ]" vs. "[[ ]]" in Bash shell
body: <p>This may be answered already but I am going to ask it anyways. I have two versions of a script (<code>comp.sh</code>)-</p>
  
  <pre><code>#!/bin/sh
  export tDay=$(date '+%Y%m%d')
  newfile="filename_$tDay"
  filename="filename_20120821100002.csv"
  echo $newfile $filename
  if [ $filename = *$newfile* ]
  then
    echo "Matched"
  else
    echo "Not Matched!"
  fi
  
  Output:
  $ ./comp.sh
  filename_20120821 filename_20120821100002.csv
  Not Matched!
  </code></pre>
  
  <p>And</p>
  
  <pre><code>#!/bin/sh
  export tDay=$(date '+%Y%m%d')
  newfile="filename_$tDay"
  filename="filename_20120821100002.csv"
  echo $newfile $filename
  if [[ $filename = *$newfile* ]]
  then
    echo "Matched"
  else
    echo "Not Matched!"
  fi
  
  $ comp.sh
  filename_20120821 filename_20120821100002.csv
  Matched
  </code></pre>
  
  <p>Could someone explain me Why the difference?</p>
  
  <p>Also - under what circumstances should <code>[ ]</code> be used vs. <code>[[ ]]</code> and vice versa?</p>