Variable does not exist if it's not set. For example,
unset var
echo ${var?"this is not set"}
-bash: var: this is not set
The shell displays an error message if var is not set. The echo is not executed. (Check the bash man page for ways to check and assign values to a variable that exists, but may or may not have a value, or one that doesn't exist.)
The more usual case is often substitution without an error, and would be handled like this:
unset var
echo ${var:-This is a new value}
This is a new value
Variable exists and has a value. For example,
var=123
echo ${var?"this is not set"}
123
Variable exists but is empty ("")
var=
echo ${var?"this is not set"}
The echo outputs the value of var, which is nothing, followed by its usual newline
Assigning a value is just like this:
var=123
echo $var
123
declare is used to assign attributes to a variable (check the bash man page for typeset or declare under the **shell builtin commands** for details.