Variable Substitution

In the previous chapter, you learned about a basic form of variable substitution, namely how to retrieve the value of a variable using the $ meta-character. In addition to this, the shell provides several other advanced forms of variable substitution that enable shell programs to manipulate the value of a variable based on its state.

There are two broad categories of advanced variable substitution:

  • Actions taken when a variable has a value

  • Actions taken when a variable does not have a value

The actions can range from one time value substitution to aborting the script. These categories are broken into four forms of variable substitution. These forms are summarized in Table 9.2.

Table 9.2. Advanced Variable Substitution
Name ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.