Is double square brackets [[ ]] preferable over single square brackets [ ] in Bash?

前端 未结 9 2054
情话喂你
情话喂你 2020-11-22 03:58

A co-worker claimed recently in a code review that the [[ ]] construct is to be preferred over [ ] in constructs like

if [ \"`id -         


        
9条回答
  •  醉话见心
    2020-11-22 04:52

    From Which comparator, test, bracket, or double bracket, is fastest? (http://bashcurescancer.com)

    The double bracket is a “compound command” where as test and the single bracket are shell built-ins (and in actuality are the same command). Thus, the single bracket and double bracket execute different code.

    The test and single bracket are the most portable as they exist as separate and external commands. However, if your using any remotely modern version of BASH, the double bracket is supported.

提交回复
热议问题