Command substitution

bash offers a handy ability to do command substitution. This feature allows you to replace the result of a command with a script. For example, wherever $(command) is found, its output will be substituted. This output could be assigned to a variable, as in the system information returned by the command uname –a:

$ SYSTEMSTRING=$(uname -a)
Linux #1 SMP Wed May 7 16:50:09 \
EDT 2008 i686 athlon i386 GNU/Linux

Another form of command substitution is `command`. The result is the same, except that the back quote (or backtick) syntax has some special rules regarding metacharacters that the $(command) syntax avoids. Refer to the bash manual at for more information.

Get LPI Linux Certification in a Nutshell, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.