What's the difference between -> result=$(ls -l) (or) -> result=`ls -l`
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`
Please check out http://nixcraft.com/shell-scripting/13288-loop-input-backticks-vs-differences.html#post19804 for a nice explanation of this case.
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:
- bash
- osx
- free bsd
精彩评论