Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 更好地引用shell脚本上执行的命令_Linux_Shell - Fatal编程技术网

Linux 更好地引用shell脚本上执行的命令

Linux 更好地引用shell脚本上执行的命令,linux,shell,Linux,Shell,我不确定这两者之间的区别,以及哪一个是在shell脚本中执行命令的更好引用 例如,我有两个例子: echo "The name of the computer is `uname -n`" echo "The name of the computer is $(uname -n)" 哪一个更好?还是没有区别?通常建议使用$(…)一个,因为它嵌套起来更容易。比较: date -d "1970-01-01 $(echo "$(date +%s)-3600"|bc) sec UTC" date -

我不确定这两者之间的区别,以及哪一个是在shell脚本中执行命令的更好引用

例如,我有两个例子:

echo "The name of the computer is `uname -n`"
echo "The name of the computer is $(uname -n)"
哪一个更好?还是没有区别?

通常建议使用
$(…)
一个,因为它嵌套起来更容易。比较:

date -d "1970-01-01 $(echo "$(date +%s)-3600"|bc) sec UTC"

date -d "1970-01-01 `echo \"\`date +%s\`-3600\"|bc` sec UTC "
通常推荐使用
$(…)
一个,因为它更容易嵌套。比较:

date -d "1970-01-01 $(echo "$(date +%s)-3600"|bc) sec UTC"

date -d "1970-01-01 `echo \"\`date +%s\`-3600\"|bc` sec UTC "

+1快速浏览时很容易混淆反勾号和单引号。有关更多信息,请参见+1。快速浏览时,很容易混淆反勾号和单引号。有关更多信息,请参阅。