View Single Post
Old 24th September 2010
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,276
Default

For entertainment, I looked up the standard to see what it says about the difference between backticks & $():

http://www.opengroup.org/onlinepubs/...xcu/chap2.html

So here's the raw meat being thrown into the lions' cage:
Code:
The $() form of command substitution solves a problem of inconsistent behaviour 
when using backquotes. For example:

Command 	Output
echo '\$x' 	\$x
echo `echo '\$x'` 	$x
echo $(echo '\$x') 	\$x

Additionally, the backquoted syntax has historical restrictions on the contents 
of the embedded command. While the new $() form can process any kind of valid 
embedded script, the backquoted form cannot handle some valid scripts that 
include backquotes. For example, these otherwise valid embedded scripts do 
not work in the left column, but do work on the right:


echo `                         echo $(
cat <<\eof                     cat <<\eof
a here-doc with `              a here-doc with )
eof                            eof
`                              )

echo `                         echo $(
echo abc # a comment with `    echo abc # a comment with )
`                              )

echo `                         echo $(
echo '`'                       echo ')'
`                              )

Because of these inconsistent behaviours, the backquoted variety of command 
substitution is not recommended for new applications that nest command substitutions 
or attempt to embed complex scripts.
Reply With Quote