title: Using unset vs. setting a variable to empty
body: <p>I'm currently writing a bash testing framework, where in a test function, both standard bash tests (<code>[[</code>) as well as predefined matchers can be used. Matchers are wrappers to '[[' and besides returning a return code, set some meaningful message saying what was expected.</p>
  
  <p>Example:</p>
  
  <pre><code>string_equals() {
      if [[ ! $1 = $2 ]]; then
              error_message="Expected '$1' to be '$2'."
  
              return 1
      fi
  }
  </code></pre>
  
  <p>So, when a matcher is used, and it fails, only then an error_message is set.</p>
  
  <p>Now, at some point later, I test whether the tests succeeded. If it succeeded, I print the expectation in green, if it failed in red.</p>
  
  <p>Furthermore, there may be an error_message set, so I test if a message exists, print it, and then unset it (because the following test may not set an <code>error_message</code>):</p>
  
  <pre><code>if [[ $error_message ]]; then
      printf '%s\n' "$error_message"
  
      unset -v error_message
  fi
  </code></pre>
  
  <p>Now my question is, if it is better to unset the variable, or to just set it to '', like</p>
  
  <pre><code>error_message=''
  </code></pre>
  
  <p>Which one is better? Does it actually make a difference? Or maybe should I have an additional flag indicating that the message was set?</p>