Prev | Current Page 189 | Next

Christopher Negus

"Linux Bible, 2008 Edition: Boot up to Ubuntu, Fedora, KNOPPIX, Debian, openSUSE, and 11 Other Distributions"


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
55
Running Commands from the Shell 2
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.


Pages:
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201