title: Check if the previous command was "valid"
body: <p>I have a function defined in <code>.bashrc</code> that displays whether or not the previous command completed successfully or not (simplified from <a href="https://gist.github.com/IQAndreas/5d22728244b6cbcf59b4">the full version</a>):</p>
  
  <pre><code>function previous_command_status()
  {
      if [ $? -eq 0 ]; then
          echo "Command successful"
      else
          echo "Command failed with exit code $exit_code"
      fi
  }
  
  PROMPT_COMMAND="previous_command_status"
  </code></pre>
  
  <p>The problem is, <code>Command successful</code> gets displayed immediately when I start the prompt, even if I haven't "officially" run any commands yet. Second (and for the same reason), the script displays <code>Command successful</code> (or the output of the last "real" command) even if all I did was hit the return button without actually executing a command (<a href="https://gist.github.com/IQAndreas/2d0c2e0bfc9a5a0c1dc1">example output</a>).</p>
  
  <p>How I can get the script to only display the message if a command was actually run?</p>