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

后端 未结 6 1755
误落风尘
误落风尘 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:36

    "What's the difference if any between the two methods?"

    Make attention to this behaviour:

    A="A_VARIABLE"
    echo "$(echo "\$A")"
    echo "`echo "\$A"`"
    

    You will get these results:

    $A
    A_VARIABLE
    

     

提交回复
热议问题