Get in touch

Send an email to: lammers@gmail.com.
Or find me online at: Github, X

Single vs double brackets

In Bash scripts both single [ and double brackets [[ can used for conditionals. Only single brackets are POSIX compliant, however most modern shells support double brackets as well.

The biggest benefit of using double brackets is that doesn't split variables, so we don't have to wrap them in quotes.

# Single brackets: Need to wrap variable in quotes
[ -e "$FILE" ]

# Double brackets
[[ -e $FILE ]]

In general it's considered safer and less error-prone to use double brackets. For me it will be the default.

Run man test in the shell to open the manual for []