Checking if the first argument passed to a bash script is set?
<p>I'm attempting to see whether the first argument passed to my script is set.  I used the instructions found here to create a test:
<a href="https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash">How to check if a variable is set in Bash?</a></p>

<p>Here's my script:</p>

<pre><code>var=$1
if [ -z ${var+x} ]; then echo "var is unset"; else echo "var is set to '$var'"; fi
</code></pre>

<p>Suppose I run it without any arguments:</p>

<pre><code>ole@MKI:./test.sh
var is set to ''
</code></pre>

<p>Suppose I run it with an argument:</p>

<pre><code>ole@MKI:./test.sh foo
var is set to 'foo'
</code></pre>

<p>In neither case does it report that the var is unset.</p>

<p>Thoughts?</p>

<p>TIA,
Ole</p>