开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜