title: Bash if statement produces different result with exclamation mark in different positions
body: <p>My first question is <strong>why putting <code>!</code> in the front of if statement</strong> fails to produce syntax error when <code>status</code> is not double quoted. That is how is <code>[ ! $x = "string" ]</code> different from 
  <code>[ $x != "string" ]</code>? </p>
  
  <p>My script is as follows.</p>
  
  <pre><code>#!/bin/bash
  
  status=" "
  
  # Comparison 1: without error
  echo "-----Comparison 1-----"
  if [ ! $status = "success" ]
  then echo 'Error: status was not success but: ' $status
  else
    echo "The status is success."
  fi
  echo "-----Comparison 2-----"
  # Comparison 2: with error message but still shows success
  if [ $status != "success" ]
  then echo 'Error: status was not success but: ' $status
  else
    echo "The status is success."
  fi
  echo "-----Comparison 3-----"
  # Comparison 3: Correct result after quoting status
  if [ ! "$status" == "success" ]
  then echo 'Error: status was not success but: ' $status
  else
    echo "The status is success."
  fi
  echo "-----Comparison 4-----"
  # Comparison 4: Correct result after quoting status
  if [ "$status" != "success" ]
  then echo 'Error: status was not success but: ' $status
  else
    echo "The status is success."
  fi
  </code></pre>
  
  <p>The output is </p>
  
  <pre><code>-----Comparison 1-----
  The status is success.
  -----Comparison 2-----
  ./test2.sh: line 14: [: !=: unary operator expected
  The status is success.
  -----Comparison 3-----
  Error: status was not success but:
  -----Comparison 4-----
  Error: status was not success but:
  </code></pre>
  
  <p>Additional questions</p>
  
  <ul>
  <li>Why does it produce <code>"The status is success."</code> in <code>Comparison 2</code> after a syntax error? How would a syntax error in an if statement affects the evaluated result of such if statement?</li>
  </ul>
  
  <p>p.s. I know we need <code>""</code> around <code>$status</code> to make output right.</p>