When should I use [ vs [[ in Bash (single vs double brackets)?

Single bracket is the traditional form, and is often implemented as an external command. Double bracket is a bash (and ksh and zsh) extension, is not in POSIX, and has the advantage of cleaner syntax (see below) and not using a separate process.

One of the syntax differences is that < and > operators (note: not standard POSIX) don't need to be escaped or quoted to avoid reading as a redirect operator. Also, [ requires some tricks in case one of the strings might be empty or begin with a hyphen. This is why you see scripts do something like [ "x$ASD" == xValue ] whereas with bash they could simply use [[ $ASD == Value ]]. Note that the "x" trick is not strictly necessary with a POSIX-compliant command testing only one thing, see this question for more details about it.

The bash FAQ has for more information about the differences. This has also been answered on another stack exchange site.

Tags:

Bash

Posix