There is a built-in statement requiring a variable to be set. This will lead to the output of the script if it is not.
tag=${1?Need a value}
This is usually used with : no-op next to the start of the script.
: ${1?Need a value}
The merge of "unset or empty" is slightly different. There is no similar construction to exit an empty but set value, but you can easily use the associated ${var:-default} , which expands to $var if it is installed and not empty, and default otherwise. There is also ${var-default} , which produces only default if the variable is not set correctly.
This can be especially useful if you want to use set -u , but you need to deal with a possible undefined variable:
case ${var-} in '') echo "$0: Need a value in var" >&2; exit 1;; esac
I somewhat prefer case over if [ "${var-}" = '' ] , mainly because it bothers me to wrap double quotes around ${var-} , and the sluggish case of the value is in $var , which is interpreted as an option for [ and gives an error message when you least expect it. (In Bash, [[ does not have these problems, but I prefer to stick with the POSIX shell when I can.)
source share