title: Test for a Bash variable being unset, using a function
body: <p>A simple Bash variable test goes:</p>
  <pre><code>${varName:?    &quot;${varName} is not defined&quot;}
  </code></pre>
  <p>I'd like to reuse this, by putting it in a function. How can I do it?</p>
  <p>The following fails</p>
  <pre><code>#
  # Test a variable exists
  tvar(){
   val=${1:?    &quot;${1}    must be defined, preferably in $basedir&quot;}
   if [ -z ${val}  ]
       then
       echo Zero length value
   else
       echo ${1} exists, value ${1}
   fi
  }
  </code></pre>
  <p>I.e., I need to exit if the test fails.</p>