What is the difference between $(command) and `command` in shell programming?

后端 未结 6 1750
误落风尘
误落风尘 2020-11-22 01:15

To store the output of a command as a variable in sh/ksh/bash, you can do either

var=$(command)

or

var=`command`

6条回答
  •  死守一世寂寞
    2020-11-22 01:42

    When the older back-tick form is used, backslash retains its literal meaning except when followed by $, `, or \. The first back-tick not preceded by a backslash terminates the command substitution.

    When using the newer $(command) form, all characters between the parentheses make up the command; none are treated specially.

    Both forms can be nested, but the back-tick variety requires the following form.

    `echo \`foo\`` 
    

    As opposed to:

    $(echo $(foo))
    

提交回复
热议问题