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

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

    They behave the same. The difference is syntactical: it's easier to nest $() than ``:

    listing=$(ls -l $(cat filenames.txt))
    

    vs.

    listing=`ls -l \`cat filenames.txt\``
    

提交回复
热议问题