Are you perhaps trying to distinguish between a variable that is explicitly empty (X="") vs. one that was never set? That can be done, but it requires paying particular attention to the paragraph
"When not performing substring expansion, using the forms documented below, bash tests for a parameter that is unset or null. Omitting the colon results in a test only for a parameter that is unset."
in the
Parameter Expansion section of the
bash manpage, and substituting something unique for an unset parameter.
This little script tests for whether $1 is explicitly null, was not passed at all, or has some other value:
Code:
#!/bin/bash
case "${1-_is_unset_}" in
"")
echo "is null";;
_is_unset_)
echo "is not set";;
*)
echo "has a value \"$1\"";;
esac