Command substitution in the C shell
In command substitution, the shell executes a specified command and replaces that command with its output.
To perform command substitution in the C shell, enclose the
command or command string in backquotes (` `
). The shell
normally breaks the output from the command into separate words at blanks,
tabs, and newline characters. It then replaces the original command with this
output.
` `
) around
the date command indicate that the output of the command
will be substituted: echo The current date and time is: `date`
The current date and time is: Wed Apr 8 13:52:14 CDT 1992
The C shell performs command substitution selectively on the arguments of built-in shell commands. This means that it does not expand those parts of expressions that are not evaluated. For commands that are not built-in, the shell substitutes the command name separately from the argument list. The substitution occurs in a child of the main shell, but only after the shell performs input or output redirection.
If a command string is surrounded by " "
, the shell
treats only newline characters as word separators, thus preserving blanks
and tabs within the word. In all cases, the single final newline character
does not force a new word.