title: Compare empty string inside if in bash (C style vs Bash)
body: <p>I was learning bash when I stuck comparing strings inside if statement. </p>
  
  <p>Script: <em>shiftDemo.sh</em></p>
  
  <pre><code>  1 #!/bin/bash
    2 
    3 #using shift keyword to shift CLA 
    4 
    5 while true
    6 do
    7         if [ "$1" = "" ]     #change this statement wrt below cases
    8         then
    9                 exit
   10         fi
   11         echo '$1 is now ' "$1"
   12         shift
   13 done
  </code></pre>
  
  <p>I used the following methods:</p>
  
  <p>1.if (( "$1" = "" ))</p>
  
  <p>2.if [ "$1" = "" ]</p>
  
  <p><strong>Observations:</strong></p>
  
  <p>1a) <code>$ bash shiftDemo.sh first second third</code></p>
  
  <pre><code>`shiftDemo.sh: line 7: ((: =  : syntax error: operand expected (error token is "=  ")`
  </code></pre>
  
  <p>1b) <code>$ sh shiftDemo.sh first second third</code></p>
  
  <pre><code>shiftDemo.sh: 7: shiftDemo.sh: first: not found
  $1 is now  first
  shiftDemo.sh: 7: shiftDemo.sh: second: not found
  $1 is now  second
  shiftDemo.sh: 7: shiftDemo.sh: third: not found
  $1 is now  third
  shiftDemo.sh: 7: shiftDemo.sh: : Permission denied
  $1 is now  
  shiftDemo.sh: 12: shift: can't shift that many
  </code></pre>
  
  <p>2)In this case, if statement runs fine with <strong>both the shells</strong> &amp; gives correct output. </p>
  
  <pre><code>$ bash shiftDemo.sh first second third
  $1 is now  first
  $1 is now  second
  $1 is now  third
  
  $ sh shiftDemo.sh first second third
  $1 is now  first
  $1 is now  second
  $1 is now  third
  </code></pre>
  
  <p>Based on the above observations, my doubts are:</p>
  
  <ol>
  <li><p>What is wrong with case 1. How can I correct it (I want to use C style syntax throughout my script).</p></li>
  <li><p>Which syntax is preferred so that it will work with both sh &amp; bash shell ? </p></li>
  </ol>