简体   繁体   English

如何在Linux Shell中使用反引号?

[英]How to use backticks in linux shell?

From the 《Bash Guide for Beginners》 : 摘自《 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.

In this passage, there is one sentence I don't understand. 在这段中,有一个我听不懂的句子。

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

Can you provide examples to explain it in more detail? 您能否提供示例以更详细地说明它? Thank you very much! 非常感谢你!

The author meant the first not-escaped backtick. 作者指的是第一个没有逃脱的背景。

Dummy example: 虚拟示例:

echo `command \` arg`

First the backtick between command and arg is escaped with backslash, so the substitution is closed by the last backtick. 首先,命令和arg之间的反引号用反斜杠转义,因此替换由最后一个反引号关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM