I am not sure whether you want to detect if a variable is unset or empty. These are 2 different things. Specifically, a variable can be set but be empty:
$ var=""
$ if [ -z "$var" ]; then echo empty; fi
$ empty
The same is going on here:
#!/usr/bin/env bash
set -u
echo $1
Test:
$ ./test.sh
./test.sh: line 4: $1: unbound variable
$ ./test.sh ""
$
Or here:
#!/usr/bin/env bash
tag=${1?Need a value}
echo $tag
Test:
$ ./se.sh
./se.sh: line 3: 1: Need a value
$ ./se.sh ""
$
Other posters have presented correct ways to detect an unset and empty variable. Personally I like this way of detecting empty and unset variables:
#!/usr/bin/env bash
if [ "$1"A = A ]
then
echo variable is empty or unset
fi
Test:
$ ./empty.sh ""
variable is empty or unset
$ ./empty.sh
variable is empty or unset
$ ./empty.sh 1
$
var=" "be considered empty or not?