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

后端 未结 8 992
梦谈多话
梦谈多话 2020-11-22 05:05

There are two ways to capture the output of command line in bash:

  1. Legacy Bourne shell backticks ``:

    var=`command`
             
    
    
            
8条回答
  •  盖世英雄少女心
    2020-11-22 05:43

    This is a legacy question, but I came up with a perfectly valid example of $(...) over `...`.

    I was using a remote desktop to windows running cygwin and wanted to iterate over a result of a command. Sadly, the backtick character was impossible to enter, either due to the remote desktop thing or cygwin itself.

    It's sane to assume that a dollar sign and parentheses will be easier to type in such strange setups.

提交回复
热议问题