什么是$(命令),并在shell编程`command`之间的区别? [英] What's the difference between $(command) and `command` in shell programming?

查看:171
本文介绍了什么是$(命令),并在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.

查看<一个href=\"http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html#tag_23_02_06_03\">POSIX SPEC上的各种差异的详细信息。

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

这篇关于什么是$(命令),并在shell编程`command`之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆