Skip to Content
Small, Sharp Software Tools
book

Small, Sharp Software Tools

by Brian P. Hogan
June 2019
Intermediate to advanced
328 pages
7h 27m
English
Pragmatic Bookshelf
Content preview from Small, Sharp Software Tools

Using Command Substitution

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The VimL Primer

The VimL Primer

Benjamin Klein
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz

Publisher Resources

ISBN: 9781680507003Errata Page