Chapter 10: Expansions and Substitutions

Tilde Expansion

  • ~ represents $HOME environment variable
  • ~- represents $OLDPWD, and will show the previous directory you were in (if you had recently changed directories).

Brace Expansion

It is used to generate strings at the command line or in a shell script. For example, touch file{0..12} will create file1, file2,.., file12.

Parameter Expansion

We’ve seen this while reading variables - parameter expansion lets us recall stored values:

1 a="Hello World"
2 echo ${a}
3 echo $a

Pattern Substitution

It is a special case of parameter expansion.

1 greeting="hello there"
2 # will replace there with everybody
3 echo ${greeting/there/everybody}

Command Substitution

Allows us to use the output of a command within another command. For example,
echo "$(uname -r)".