title: bash if logical boolean string
body: <p>I am <em>not</em> looking for a different way to accomplish the apparent intention.  I'm looking to <em>understand</em> why this <em>exact</em> syntax is not working.</p>
  
  <pre><code>[root@lvs ~]# while true;do
  &gt; echo "Would you like the script to check the second box ([y]n)?"
  &gt; read ans
  &gt;         if [ "$ans" == "n" ];then
  &gt;                 echo
  &gt;                 echo "bye"
  &gt;                 exit
  &gt;         elif [ "$ans" != "" -o "$ans" != "y" ];then
  &gt;                 echo "Invalid entry..."
  &gt;         else
  &gt;                 break
  &gt;         fi
  &gt; done
  Would you like the script to check the second box ([y]n)? **"Should have continued"**
  
  Invalid entry...
  Would you like the script to check the second box ([y]n)? **"Should have continued"**
  y
  Invalid entry...
  Would you like the script to check the second box ([y]n)? **"Correct behavior"**
  alskjfasldasdjf
  Invalid entry...
  Would you like the script to check the second box ([y]n)? **"Correct behavior"**
  n
  
  bye
  </code></pre>
  
  <p>Here's a reference that's identical to so many others i found. I <em>understand</em> what it's doing, it's using the non logical's for AND and OR when everything I've read said that it should be using logical bools.</p>
  
  <p><a href="http://www.groupsrv.com/linux/about140851.html" rel="nofollow">http://www.groupsrv.com/linux/about140851.html</a></p>
  
  <p>Ok so here it is, with Nahuel's suggestion behaving how I had originally expected it to:</p>
  
  <pre><code>[root@lvs ~]# while true;do
  &gt; echo "Would you like the script to check the second box ([y]n)?"
  &gt; read ans
  &gt;         if [ "$ans" = "n" ];then
  &gt;                 echo
  &gt;                 echo "bye!"
  &gt;                 exit
  &gt;         elif [ "$ans" != "" -a "$ans" != "y" ];then
  &gt;                 echo "Invalid entry..."
  &gt;         else
  &gt;                 break
  &gt;         fi
  &gt; done
  Would you like the script to check the second box ([y]n)?
  asdfad
  Invalid entry...
  Would you like the script to check the second box ([y]n)?
  
  [root@lvs ~]# while true;do
  &gt; echo "Would you like the script to check the second box ([y]n)?"
  &gt; read ans
  &gt;         if [ "$ans" = "n" ];then
  &gt;                 echo
  &gt;                 echo "bye!"
  &gt;                 exit
  &gt;         elif [ "$ans" != "" -a "$ans" != "y" ];then
  &gt;                 echo "Invalid entry..."
  &gt;         else
  &gt;                 break
  &gt;         fi
  &gt; done
  Would you like the script to check the second box ([y]n)?
  y
  [root@lvs ~]# while true;do
  &gt; echo "Would you like the script to check the second box ([y]n)?"
  &gt; read ans
  &gt;         if [ "$ans" = "n" ];then
  &gt;                 echo
  &gt;                 echo "bye!"
  &gt;                 exit
  &gt;         elif [ "$ans" != "" -a "$ans" != "y" ];then
  &gt;                 echo "Invalid entry..."
  &gt;         else
  &gt;                 break
  &gt;         fi
  &gt; done
  Would you like the script to check the second box ([y]n)?
  n
  
  logout
  </code></pre>