O'Reilly logo

Using csh & tcsh by Paul DuBois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deferred Command Substitution

In the most direct form of command substitution, the output of a command that generates arguments is substituted immediately into the command that uses the arguments. The strategy of saving the arguments in a file and inserting the file's contents into another command decouples argument generation from argument use, which in effect defers command substitution. This method was used in the previous section for reasons of efficiency (to avoid running a lengthy find command more than once), but the method is useful in other situations as well. For example, you can examine the argument list to check it, or to modify the list before passing it to another command. These techniques are discussed below.

Verifying the Argument List

You should not always put a backquoted command directly into the command that uses its output. The argument-generating command might produce unexpected output, or no output at all, as discussed below.

Dealing with unexpected output

The argument-generating command might not produce the type of output you expect. The single-character difference between the following command lines is significant:

% vi `grep -li gaboon *`
% vi `grep -i gaboon *`

The grep command in the first command line lists only the names of the files containing lines matching the search string. This is the desired output. The grep command in the second command line lists the matching lines themselves. This is not the desired output. If you inadvertently forget to add the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required