简体   繁体   中英

How to use backticks in linux shell?

From the 《Bash Guide for Beginners》 :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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