Usage of the
$() is generally recommended in
bash, but I wouldn't go as far as calling backticks
deprecated.
Regarding compatibility issues, $() is a part of POSIX, so I wouldn't wory about anything but very old systems.
Personally, I prefer
$() and usually
recommend it over the backticks. Now both can do the same, so if anyone prefers backticks, I'm fine with that.
In addition to the advantages already mentioned, Here's a few other things I like about the "
new" syntax:
1/ Consistent syntax with the other "
variable-like" expressions:
Code:
$foo # a variable
${foo,,} # a variable obtained from string manipulation
$((foo)) # a variable obtained from an arithmetic expression
$(foo) # a variable obtained from a command
$(<foo) # a variable obtained from a file
2/ Most of the times you use command substitution, you should put it within double quotes, and (in my opinion)
is nicer and more readable than
3/ most text editors will highlight matching pairs of parentheses, but not backticks.