title: In Bash, how do I test if a variable is defined in "-u" mode
body: <p>I just discovered <code>set -u</code> in bash and it helped me find several previously unseen bugs. But I also have a scenario where I need to test if a variable is defined before computing some default value. The best I have come up with for this is:</p>
  
  <pre><code>if [ "${variable-undefined}" == undefined ]; then
      variable="$(...)"
  fi
  </code></pre>
  
  <p>which works (as long as the variable doesn't have the string value <code>undefined</code>).  I was wondering if there was a better way?</p>