(edit: question more accurate based on @Michael feedback)
In bash, I often use parameter expansion: the following commands print \"default value
\" when
Just remove the colon. If you use :-
in your substitution the default value will be used if the variable is null, an empty string or it does not exist, but just using -
on its own will only substitute the default value if the variable has not been defined.
# var1=default
# var2=
# echo var2 is ${var2:-$var1}
var2 is something
# echo var3 is ${var3:-$var1}
var3 is something
# echo var2 is ${var2-$var1}
var2 is
# echo var3 is ${var3-$var1}
var3 is something