Covers how to distinguish between an unset variable and a variable explicitly set to an empty string in Bash/POSIX shell scripts. Two approaches are presented: a POSIX-compliant method using parameter expansion (`${var+x}`) that works even with `set -o nounset`, and a Bash 4.2+ built-in check using the `-v` flag. Both approaches are shown with if/elif and case statement variants, along with example outputs for all three states: unset, empty, and non-empty.
Sort: