What is the benefit of using $() instead of backticks in shell scripts?

10/14 00:30
阅读数 0

问题:

There are two ways to capture the output of command line in bash :有两种方法可以在bash捕获命令行的输出:

  1. Legacy Bourne shell backticks `` :旧版 Bourne shell 反引号`` :

    var=`command`
  2. $() syntax (which as far as I know is Bash specific, or at least not supported by non-POSIX old shells like original Bourne) $()语法(据我所知是 Bash 特定的,或者至少不受像原始 Bourne 这样的非 POSIX 旧 shell 的支持)

    var=$(command)

Is there any benefit to using the second syntax compared to backticks?与反引号相比,使用第二种语法有什么好处吗? Or are the two fully 100% equivalent?或者两者完全 100% 等价?


解决方案:

参考一: https://en.stackoom.com/question/deJm
参考二: https://stackoom.com/question/deJm
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部