MPE/iX Shell and Utilities Reference Manual, Vol 2
sh(1) MPE/iX Shell and Utilities sh(1)
To process this command line, sh first executes the cat command and collects its standard
output. The shell then breaks this output into arguments and puts the result into the command
line of the ls command. The previous command therefore lists the attributes of all files, the
names of which are contained in the file list.
This syntax is easy to type, but is not useful if you want to put one command substitution
inside another (nesting command substitutions). A more useful syntax is
$(command)
as in
vi $(fgrep -l function $(find . -name ’*.c’))
This command uses find to search the current directory and its subdirectories to find all files,
the names of which end in .c. It then uses fgrep to search each such file for those that con-
tain the string function. Finally, it calls Vi to edit each such file.
There is an historical inconsistency in the backquoting syntax. A backslash (\) within a
backquoted command is interpreted differently depending on its context. Backslashes are
interpreted literally unless they precede a dollar sign ($), grave accent (`), or another
backslash (\); in these cases, the leading backslash becomes an escape character to force the
literal interpretation of the $, `,or\. Consequently, the command
echo ’\$x’
issued at system level produces the output
\$x
while the same command nested in a backquoted syntax
echo `echo ’\$x’`
produces the output
$x
We recommend the $(command) syntax for command substitutions.
sh performs command substitutions as if a new copy of the shell is invoked to execute the
command. This affects the behavior of $- (standing for the list of options passed to the shell).
If a command substitution contains $-, the expansion of $- does not include the –i option,
since the command is being executed by a non-interactive shell.
Commands and Utilities 1-535