Unix Shell: variable substitution 


May 29, 2007 03:48:01    Last update: May 29, 2007 03:49:54
The following applies to Bourne, Korn and Bash:

$var or ${var}Replaced by the value of var. Use braces to avoid ambiguity.
${var-value}Use the value of var if set, use value otherwise.
${var+value}Use the value of value if var is set, use nothing otherwise.
${var=value}Use the value of var if set, other wise, use value and assign value to var.
${var?value}Use the value of var; otherwise, print value to standard error and exit the current shell. If value is omitted, a standard error message is printed instead.
Share |
| Comment  | Tags