title: Portable way to check emptyness of a shell variable
body: <p>What is the portable and canonical way to test if variable is empty/undefined in a shell script? It should work in all sh-like shells. What I do now is something like:</p>
  
  <pre><code>if [ -z "$var" ] ; then
      ...
  </code></pre>
  
  <p>and for reverse, doing something when variable is not empty/undefined:</p>
  
  <pre><code>if [ -n "$var" ] ; then
      ...
  </code></pre>
  
  <p>And while these work for the scripts I write now, <strong>I'd like to know a way, that will work in any reasonably compatible <em>sh</em>-like shell</strong>, even on some more obscure environment than a Linux PC with GNU userland and <em>bash</em> or <em>dash</em>.</p>
  
  <p>I'm looking for an "expert answer" from someone who is experienced in different shell environments and knows the pitfalls of different ways of doing things, not an opinion like "that should work".</p>