Replacing Variables in Bash/shell
Intro:
First of all make sure that you the variable is defined before replacing it, or in other cases determine that it is not empty, and to initialize with a default value if necessary.
Expression:Defininition
$var: replace by the value of the variable $var if defined. Otherwise nothing.
${var}: replace by the value of the variable $var if defined. Otherwise nothing. Better use this, in order to protect from certain inconsistencies when using Strings.
${var:-default}: replace by the value of the variable $ var "if defined. Otherwise the value default.
${var:+default}: Set the variable $var with the value default if defined. Otherwise leave empty.
${var:?"Message"} :replace by the value of the variable $var if defined. Otherwise, the shell displays specific error message instead of "Message".
${var:=default} : replace by the value of the variable $var if defined. Otherwise create and initialize the variable var with the Value default.