Unusual file: /bin/[

Polytropon freebsd at edvax.de
Mon Jul 29 13:54:08 UTC 2013

On Mon, 29 Jul 2013 14:25:08 +0100, Paul Macdonald wrote:
> Hi, I spotted what i'd call an unusual file in the basejail on a jail 
> install, and have since seen this on other non jailed boxes.
> -r-xr-xr-x   2 root  wheel   11488 Jun 10 12:19 [
> man [  reveals
>          test, [ -- condition evaluation utility
> just checking thats all ok, and i've not been rooted!

The "[" program is the same as the "test" program. It's
a valid file name and it's often used in shell scripts
instead of "test".

% ll /bin/test /bin/\[ 
-r-xr-xr-x  2 root  wheel  8336 2011-08-21 20:23:20 /bin/[*
-r-xr-xr-x  2 root  wheel  8336 2011-08-21 20:23:20 /bin/test*

Consider shell scripts. When you have a script with something like

	if [ -f bla.txt ]; then
		... some stuff ...

it is the same as

	if test -f bla.txt; then
		... some stuff ...

It's also often being used like

	[ -x blah.sh ] && do_something

which is identical to calling "test" and acting upon the value
of the return code.

Nothing to worry here.

YOu can _always_ counter-check by building /usr/src/bin/test
from source and compare the resulting binary. Both /bin/[
and /bin/test are usually installed as hardlinks (two file
names for one / for _the same_ file), as seen in the
corresponding Makefile:

	LINKS=  ${BINDIR}/test ${BINDIR}/[

So it's not _that_ unusual. ;-)

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list