/usr/bin/test not /usr/bin/[ anymore?

I am really puzzled: While proudly presenting some linux knowledge I could not explain why /usr/bin/test and /usr/bin/[ are on Debian and Ubuntu (and maybe other distributions) not binary and symlink but different binaries. On Ubuntu Gutsy it looks like this:

[ccm:0:~]$ ls -l /usr/bin/test
-rwxr-xr-x 1 root root 23036 2007-09-29 14:51 /usr/bin/test
[ccm:0:~]$ ls -l /usr/bin/\[
-rwxr-xr-x 1 root root 25024 2007-09-29 14:51 /usr/bin/[
[ccm:0:~]$ md5sum /usr/bin/test
d83583f233cb4a014c2e9faef6bb9b32  /usr/bin/test
[ccm:0:~]$ md5sum /usr/bin/\[
b1e9282a48978a17fb7479faf7b8c8b7  /usr/bin/[

When playing around with them, they even behave different:

[ccm:0:~]$ /usr/bin/test --version
[ccm:0:~]$ /usr/bin/\[ --version
[ (GNU coreutils) 5.97

On Debian, Fedora, RedHat it looks the same. It puzzles me as just some weeks ago I read one of them is actually a symlink and think I the first test I made showed me machine where it behaved that way.

So maybe someone can update me why these binaries are different now. Guess there cannot be good reason as „man test“ and „man [“ show the same document:

ls -l /usr/share/man/man1/\[.1.gz
lrwxrwxrwx 1 root root 9 2007-12-04 19:20 /usr/share/man/man1/[.1.gz -> test.1.gz

And when answering this: „/usr/bin/test“ is part of coreutils, but /usr/bin/[ ?

Powered by ScribeFire.

5 Gedanken zu “/usr/bin/test not /usr/bin/[ anymore?

  1. Hi !
    On my fedora core 8 [ and test are different too :

    ls /usr/bin/test /usr/bin/\[ -l
    -rwxr-xr-x 1 root root 31404 déc 5 14:25 /usr/bin/[
    -rwxr-xr-x 1 root root 29032 déc 5 14:24 /usr/bin/test

  2. You’ll find the answer in coreutils test.c, which gets compiled twice.

    The reason why these mustn’t be identical (apart from different behaviour for –help and –version) should be clear from the following example:

    if test -z $MYVAR; then
    ..
    fi

    vs.

    if [ -z $MYVAR; then
    ..
    fi

    The first is valid, the second is not and *must* fail.

    HTH,
    Stefan.

  3. @Malcolm:

    Think the comment in Savannah says it: Depending on the file name is not compatible to the gnu coreutils guidelines – that is why those two programs have been split.

Schreib einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *