The Bash manual notes that:
The POSIX $() form of command substitution is implemented (see Command Substitution), and preferred to the Bourne shell’s `` (which is also implemented for backwards compatibility).
$(...) is preferred over
`...` in anything new and Bash-specific you're writing¹. Backtick substitution doesn't nest well (you have to escape them), and has some slightly odd quoting behaviour. You can nest
$(... $(...) ...) arbitrarily much without issue. The manual describes the behaviour of the two as:
When the old-style backquote form of substitution is used, backslash retains its literal meaning except when followed by ‘$’, ‘`’, or ‘\’. The first backquote not preceded by a backslash terminates the command substitution. When using the $(command) form, all characters between the parentheses make up the command; none are treated specially.
It's usually considered best practice to quote all string expansions to avoid word-splitting issues, including in places where it isn't strictly required, so
"$(...)" is also better practice here.
Finally, two relevant parts from that same wooledge page:
- It's also time you forgot about
`...`. It isn't consistent with the syntax of Expansion and is terribly hard to nest without a dose of painkillers. Use
- And for heaven's sake, "Use more quotes!" Protect your strings and parameter expansions from word splitting. Word splitting will eat your babies if you don't quote things properly.
¹Actually, even in POSIX
sh scripts, these are considered best practice. There are still weaker shells around, but you'll know if you're going to encounter them.