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: How to check if a variable is set in Bash?
Here's my script:
var=$1
if [ -z ${var+x} ]; then echo "var is unset"; else echo "var is set to '$var'"; fi
Suppose I run it without any arguments:
ole@MKI:./test.sh
var is set to ''
Suppose I run it with an argument:
ole@MKI:./test.sh foo
var is set to 'foo'
In neither case does it report that the var is unset.
Thoughts?
TIA, Ole