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

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

    There is little difference, except for what unescaped characters you can use inside of the command. You can even put `...` commands inside $(...) ones (and vice versa) for a more complicated two-level-deep command substitution.

    There is a slightly different interpretation of the backslash character/operator. Among other things, when nesting `...` substitution commands, you must escape the inner ` characters with \, whereas with $() substition it understands the nesting automatically.

提交回复
热议问题