Test, [, and [[ (2020)

In Unix systems, there is a binary called ‘[‘ that serves as a helper tool in evaluating expressions in the shell. It can be used to compare strings, numbers, and check conditions on files. The reason for having two names, ‘[‘ and ‘test’, for the same binary is not clear, but it may be to make the syntax more pleasing. The test binary checks its argv[0] to determine if it’s invoked as test or ‘[‘. Additionally, there is a Bash extension called ‘[[‘, which replaces the use of ‘[‘ and provides additional features like regular expression matches. However, if you’re writing a portable shell script, it’s best to stick with ‘[‘. Interestingly, the shell also has its own expressions using !, &&, and || operators, which work on command exit statuses. This means you can combine test expressions and shell expressions in one invocation. It’s up to you whether to be amused or horrified by this.

https://jmmv.dev/2020/03/test-bracket.html

To top