什么是$(命令),并在shell编程`command`之间的区别?

问题描述:

在SH / KSH / bash中存储一个命令的输出,你可以做一个变量为

In sh/ksh/bash to store the output of a command as a variable you can do either

MY_VAR=$(command)
#or you can do
MY_VAR=`command`

有什么区别,如果这两种方法之间的?

What's the difference if any between the two methods?

反引号/ gravemarks已经去赞成 $()的pcated为命令替换$ P $因为 $()可以在自己方便地窝在 $(foo的回声$(回声酒吧))。另外还有诸如如何反斜杠的反引号/ gravemark版本被解析细微的差别。

The backticks/gravemarks have been deprecated in favor of $() for command substitution because $() can easily nest within itself as in $(echo foo$(echo bar)). There are also minor differences such as how backslashes are parsed in the backtick/gravemark version.

查看POSIX SPEC上的各种差异的详细信息。

See the POSIX spec for detailed information on the various differences.