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

advertisements

In sh/ksh/bash to store the output of a command as a variable you can do either

MY_VAR=$(command)
#or you can do
MY_VAR=`command`

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


The backticks/gravemarks have been deprecated in favor of $() for command substitution because $() can easily nest within itself as in $(echo foo$(echo bar)). There are also minor differences such as how backslashes are parsed in the backtick/gravemark version.

See the POSIX spec for detailed information on the various differences.