views:

80

answers:

2

I'v run both commands and they both seem to do the same thing, is this true or is there something happening I'm not seeing?

These two appear to do the same thing:

result=$(ls -l)   
result=`ls -l`
+3  A: 

Hi,

Please check out http://nixcraft.com/shell-scripting/13288-loop-input-backticks-vs-differences.html#post19804 for a nice explanation of this case.

GeekTantra
huh ok, so looks like I was wise to manly use t=$(ls -l)Thanks guys!
Mint
Another reference: http://mywiki.wooledge.org/BashFAQ/082
Dennis Williamson
Good link, but I question their definition of "new" when saying that $() is a new syntax. It is newer than backticks, but it's been around for a *long* time.
William Pursell
+1  A: 

The bash man page says the following, under Command Substitution.

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 sub-stitution. When using the $(command) form, all characters between the parentheses make up the command; none are treated specially.

Command substitutions may be nested. To nest when using the backquoted form, escape the inner backquotes with backslashes.

Online copies of the sh man page:

Lachlan Roche