bash
This demonstrates providing a default value for a variable if it is unset or empty using parameter expansion in Bash.
echo "${foo:-"DefaultValueIfFooIsMissingOrEmpty"}" # => DefaultValueIfFooIsMissingOrEmpty # This works for null (foo=) and empty string (foo=""); zero (foo=0) returns 0. # Note that it only returns default value and doesn't change variable value.
bash internaldata manipulationsstring manipulation and expansionsparameter expansiondefault value substitution
bash
This demonstrates two ways to print the current directory in Bash: using command substitution and a built-in variable.
echo "I'm in $(pwd)" # execs `pwd` and interpolates output echo "I'm in $PWD" # interpolates the variable
bash internaldata manipulationsstring manipulation and expansionscommand substitution