Command substitution

Command substitution allows us to take the output of one command and save it to a variable. This is achieved by placing the command within parentheses which is preceded by a dollar sign $

 

var=$(command)

 

*note: ls ~ (list contents of home directory  ~) is being piped into wc -l (word count, number of lines)

 

Invoke:

./substitution.sh

 

Output:

You have 5 files in your home directory.

 

 

Traditionally carried out using `backticks`, but has now been superceded with the above parentheses method.