/bin/[

Matthew Seaman m.seaman at infracaninophile.co.uk
Sun Aug 26 14:16:22 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Jim Stapleton wrote:
> Sorry if you get this question a lot - a few searches didn't find
> results for me.
> 
> I have a "/bin/[" file in my system - I just want to make sure it's
> not a sign of someone having hacked my machine.

No -- that's perfectly alright.  If you look closely you can see
that it is in fact identical to /bin/test:

% ls -lai test '['
871508 -r-xr-xr-x  2 root  wheel  7652 Aug 18 12:31 [*
871508 -r-xr-xr-x  2 root  wheel  7652 Aug 18 12:31 test*

It's used for testing various conditions in shell scripts -- like
this for example:

   [ "x$foo" != "x" ] && echo "\$foo is set to $foo"

which could be written equivalently as:

   test "x$foo" != "x" && echo 2\$foo is set to $foo"

The curious name is historic, based on some early shells where there
was a built-in syntax using the '[' character.  Having test or [ as
an external program means that all the standard shell on FreeBSD can
 use exactly the same test syntax and theres only one copy of the
code to keep maintained in the source tree.

	Cheers,

	Matthew
	
- --
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
                                                  Kent, CT11 9PW
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG0e2e8Mjk52CukIwRCElMAJ40jLDH5y/TKKUJ7uT5Mv84LdnZgQCdG5Iy
4Y3I0l4+Hv9WMZTvl1jri64=
=xzZw
-----END PGP SIGNATURE-----


More information about the freebsd-questions mailing list