builtin [ , -bash: [: missing `]'
The [
version of the command requires ]
as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “block”, so commands look this way:
if [ $1 -eq 2 ]; then
instead of
if [ $1 -eq 2; then
See help [
:
$ help [
[: [ arg... ]
Evaluate conditional expression.
This is a synonym for the "test" builtin, but the last argument must
be a literal `]', to match the opening `['.
Notes
The
test
version does not require nor accept the final]
.You don’t need the
builtin
there. Builtins take priority over external commands, so just[
would execute the builtin. Thebuiltin
command is more useful when you have a function or alias masking[
.