Because it is a syntactical feature, it lets you use && and || operators for boolean tests and < and > for string comparisons. [ cannot do this because it is a regular command and &&, ||, <, and > are not passed to regular commands as command-line arguments.
It has a wonderful =~ operator for doing regular expression matches. With [ you might write
Keep in mind that it is a bash extension, so if you are writing sh-compatible scripts then you need to stick with [. Make sure you have the #!/bin/bash shebang line for your script if you use double brackets.
最重要的区别是代码的清晰。是的,是的,上面所说的是正确的,但是[[]]使你的代码符合你在高级语言中所期望的,特别是关于AND (,,), OR (||)和NOT (!)操作符。因此,当您在系统和语言之间切换时,您将能够更快地解释脚本,从而使您的生活更轻松。从好的UNIX/Linux参考中获取基本信息。你可能会发现一些细节在某些情况下是有用的,但你会一直欣赏清晰的代码!你更愿意读哪个剧本片段?即使断章取义,第一种选择也更容易阅读和理解。