如何在linux shell中使用反引号?

时间:2015-07-28 07:01:22

标签: linux bash

来自“Bash初学者指南”:

3.4.5. Command substitution

Command substitution allows the output of a command to replace the command itself. Command substitution
occurs when a command is enclosed like this:

$(command)

or like this using backticks:

\`command`

Bash performs the expansion by executing COMMAND and replacing the command substitution with the
standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but
they may be removed during word splitting.

    franky ~> echo `date`
    Thu Feb 6 10:06:20 CET 2003



When the old−style backquoted form of substitution is used, backslash retains its literal meaning except when
followed by "$", "`", or "\".

The first backticks not preceded by a backslash terminates the command substitution.

When using the "$(COMMAND)" form, all characters between the parentheses make up the
command; none are treated specially.

在这篇文章中,有一句我不明白。

The first backticks not preceded by a backslash terminates the command substitution.

您能提供一些示例来更详细地解释它吗? 非常感谢你!

1 个答案:

答案 0 :(得分:1)

作者意味着第一个没有逃脱的反击。

虚拟例子:

echo `command \` arg`

首先使用反斜杠转义命令和arg之间的反引号,因此替换将被最后一个反引号关闭。