-1

I have an unexpected file named [ -- a left bracket -- in my /bin file on my Mac Powerbook. I'm running Catalina. When I cat the file it looks like Apple certificate authority stuff. Most of it is unreadable, but has text in it like

Apple Certification Authority

and

PROGRAM:test PROJECT:shell_cmds-207.40.1 ??????i@[]missing ]!unexpected operator%s: %s%sclosing paren expectedargument expected%s: bad number%s: out of range)

Any idea what this could be? Seems suspicious to me -- like some source code in it based on the error messages. But don't want to just delete in case it is a file Apple needs.

hoekma
  • 139

1 Answers1

5

The open square bracket, [, is a standard executable, equivalent to test, that provides syntactic sugar when writing shell scripts (i.e. it "looks nice")

fruit="banana"
if [ banana = "$fruit" ]    # "[" really is an executable
then
    echo "Yum, yum"
fi

Or

fruit="banana"
if test pear = "$fruit"
then
    echo "Yum, yum"
fi

These are directly equivalent.

In reality your shell probably implements both [ and test directly, so that when you call them it's your shell actioning the command rather than running a separate process to do so. Again, no discernable difference to you, the user.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
  • 1
    The only discernible difference between /usr/bin/test and /usr/bin/[ is that the latter requires a final argument of ], which is not a part of shell syntax. That syntactic sugar is catching. if /usr/bin/[ 13 -lt 17 ]; then ... – Paul_Pedant Mar 14 '20 at 15:31
  • Thanks @roaima. Not sure why the I got downvoted for the question -- couldn't find anything about this file with Google searches. Appreciate taking time to help fill in the gaps for me. – hoekma Mar 14 '20 at 19:19
  • 1
    @hoekma it's very difficult to search for punctuation. I've just amended my question to try and assist future searches – Chris Davies Mar 14 '20 at 20:45