$foo
one
${foo:+bar} If $foo exists and is not null, return bar. If it doesn't exist, or is null, return a null. export foo="this is a test"
echo ${foo:+bar}
ba... {foo:?"error message"} If $foo exists and is not null, return its value. If it doesn't exist or is null, print the error message. If no error message is ... do eval echo \${$foo:?} one bash: bar: parameter null or not set bash: baz: parameter null or not set
== NOTE ==
The colon (:) in the ab... STACK :-$PWD} evaluates to $DIRSTACK if it is non-null or $PWD (the current directory) if it is null.
Table 4.1: Substitution Operators
Operator
Subst
n of this comparison operator.
----
-z
string is null, that is, has zero length
<code>
String='' # Zero-length ("null") string variable.
if [ -z "$String" ]
then
echo "\$String is null."
else
echo "\$String is NOT null."
fi # $String is null.
</code>
----
-n
string is