The command in this case...
The command in this case can include options, metacharacters, and arguments. Here is an example
of using command substitution:
$ vi $(find /home | grep xyzzy
In this example, the command substitution is done before the vi command is run. First, the find command starts at the/home directory and prints out all files and directories below that point in the file system. The output is piped to the grep command, which filters out all files except for those that include the string xyzzy in the filename. Finally, the vi command opens all filenames for editing (one at a time) that include xyzzy.
This particular example is useful if you want to edit a file for which you know the name but not the location. As long as the string is uncommon, you can find and open every instance of a filename existing beneath a point you choose in the file system. (In other words, don't use grep a from the root file system or you'll match and try to edit several thousand files.)
Expanding Arithmetic Expressions
There may be times when you want to pass arithmetic results to a command. There are two forms
you can use to expand an arithmetic expression and pass it to the shell:
$[expression] and $(expression). Here is an example:
$ echo "I am $[2008 - 1957] years old."
I am 51 years old.
The shell interprets the arithmetic expression first (2008 - 1957), and then passes that information to the echo command. The echo command displays the text, with the results of the arithmetic (51) inserted.
The continuation/full version of this article read on site www.podgrid.org - Linux Bible