Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
Using substitution in commands z/OS UNIX System Services User's Guide SA23-2279-00 |
|
Another shell feature that is useful for programmers is command
substitution. When it encounters a construct of the form:
or:
in an
input command line, the shell runs the given command.
It then puts the output of the command, after converting newlines
into spaces, back into the command line, replacing command,
and runs the new command line. This is called command substitution.You may find the $( ) syntax easier to use for long command lines. However, the ` ` (backward apostrophes) syntax is more traditional and accepted on older UNIX shells. As an example of how a programmer could use command substitution,
consider a file called srclist, containing the following list
of source code file names: alpha.c, beta.c, and gamma.c.
If you enter the command:
the
shell runs cat against the contents of srclist,
and rewrites the original command line, so that this line appears
as:
This
line is then run, with grep searching through
the given files, displaying lines that contain the string printf.
This type of construct quickly locates all references to a particular
variable or function in the source code for a program. |
Copyright IBM Corporation 1990, 2014
|