What's the difference between $(…) and `…`

前端 未结 3 770
一整个雨季
一整个雨季 2021-01-11 17:41

The question is as simple as stated in the title: What\'s the difference between the following two expressions?

$(...)
`...`

For example, a

3条回答
  •  误落风尘
    2021-01-11 18:23

    The result is the same, but the newer $() syntax is far clearer and easier to read. At least doubly so when trying to nest. Nesting is not easy with the old syntax, but works fine with the new.

    Compare:

    $ echo $(ls $(pwd))
    

    versus:

    $ echo `ls \`pwd\``
    

    You need to escape the embedded backticks, so it's quite a lot more complicated to both type and read.

    According to this page, there is at least one minor difference in how they treat embedded double backslashes.

提交回复
热议问题