Expanding Null or Unset Variables

The expression ${name} (or just $name if it is not ambiguous) expands to the value of the name variable (page 610). If name is null or not set, the shell expands ${Name} to a null string. The shell provides the following alternatives to accepting the expanded null string as the value of the variable.

  • Use a default value for the variable.

  • Use a default value and assign that value to the variable.

  • Display an error.

You can choose one of these alternatives by using a modifier with the variable name.

:– Uses a Default ...

Get A Practical Guide to Red Hat® Linux® 8 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.