27

I was just poking around in /usr/bin and I found an ELF binary file called [. /usr/bin/[. I have never heard of this file and my first thought was that it was a clever way of hiding a program, possibly a trojan. However it's present on all my CentOS servers and seems to have no manual entry. I can hazard a guess as to what it is but I was looking for a more authoritative answer...

Clint Miller
  • 1,141
Josh
  • 9,398

3 Answers3

29

It's an alternative form of the 'test' command. Mostly used in scripts.

i.e.

if [ $VAR ]
then
    echo $VAR exists!
fi
Zypher
  • 37,829
10

It's what you call when you are using something like

if [ -e foo ]; then ...

in a shell script (but most shells have it as a buildin this days). man test should give you the docs.

Florian Diesch
  • 1,814
  • 1
  • 12
  • 5
5

As others pointed out, [ is the shell's condition evaluation utility - test.

In fact, there is a manual page for that!

$ man [

should give you more details about the opening square bracket.

Btw, in OS X, [ is located in /bin/[ :)

Devy
  • 179