Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

/bin/[ ???

0 views
Skip to first unread message

Barutan Seijin

unread,
Jul 24, 2008, 5:07:42 PM7/24/08
to

ls -al /bin
total 18568
drwxr-xr-x@ 40 root wheel 1360 Jun 7 23:24 .
drwxrwxr-t 40 root admin 1428 Jul 22 10:13 ..
-r-xr-xr-x 2 root wheel 46720 Nov 25 2007 [
-rwxr-xr-x 1 root wheel 1244928 Mar 4 23:39 bash

/bin/[ ?? What is this?


--
baruta...@gmail.com

Message has been deleted

Ian Gregory

unread,
Jul 24, 2008, 5:50:23 PM7/24/08
to

It is a hard link to /bin/test (or vica versa). You can tell by noting
that they have the same inode number:

isis$ ls -i /bin/test
595245 /bin/test
isis$ ls -i /bin/[
595245 /bin/[

Type "man test" and you will see why (sort of).

Ian

--
Ian Gregory
http://www.zenatode.org.uk/ian/

Message has been deleted

Bob Harris

unread,
Jul 24, 2008, 7:49:29 PM7/24/08
to
In article <m2abg7h...@oedipa.disorg>,
Barutan Seijin <baruta...@gmail.com> wrote:

When you create a script with

if [ $# = 0 ]; then
echo no arguments
fi

You are really doing

if test $# = 0; then
echo no arguments
fi

In other words, the [ in an 'if' statement is NOT part of the 'if'
syntax, but rather a separate program called 'test'. This is
because the file '[' is either a hard link to the file 'test' or
just a copy of 'test'.

% cksum /bin/[ /bin/test
3588315430 46720 /bin/[
3588315430 46720 /bin/test

Years ago when the shell had to fit in 64 kilobytes, including all
data and the stack, it was important to leverage the use of
external programs as much as possible.

Today, the POSIX shell (as well as bash, ksh, zsh) have more
memory to work with and now support built-in [[ ... ]] syntax
parsing.

Bob Harris

0 new messages