Command substitution allows the output of a command to be stored in a variable; the command can be replaced by itself. There are two methods for performing command substitution:
- Enclosing the command within backticks, as in `command`. Use of backticks is an older method, and has two disadvantages:
- Backticks are sometimes confused with single quotation marks
- Backticks cannot be nested inside other backticks, so nested command substitution is not possible
- Enclosing the command with an initial dollar sign and parentheses, as in $(command). This overcomes the disadvantages of backticks when used in command substitution as shown in the following screenshot: