goelweb.com --> Software --> Unix utilities --> Unix shell --> Evaluation of Shell Variables
Evaluation of Shell Variables
- $var
- value of var; nothing if var undefined
- ${var}
- same; useful if alphanumerics follow variable name
- ${var-thing}
- value of var if defined; otherwise thing. $var unchanged.
- ${var=thing}
- value of var if defined; otherwise thing. If undefined, $var set to thing
- ${var?message}
- if defined, $var. Otherwise print message and exit shell. If message empty, print: var: parameter not set
- ${var+thing}
- thing if $var defined, otherwise nothing
rishi.goel@alumni.usc.edu