June 2019
Intermediate to advanced
328 pages
7h 27m
English
You can use the output of one command when invoking another command. This is handy when a program’s argument needs to be generated from another program’s output. You can do this with a feature called command substitution. You’ve already seen variable expansion with curly braces, like ${variable}, where the variable’s value is expanded. Command substitution works in a similar way. With command substitution, the output of the command replaces the command itself. To define a command substitution, you wrap the command in parentheses instead of curly braces.
You saw an example of command substitution in Building Your Prompt, when you used the tput command to emit color codes:
| | $ echo -e "$(tput setaf 6)Hello ... |