Matěj Cepl <[EMAIL PROTECTED]> said something to this effect on 09/25/2001:
> I have worked on archmail script a little bit yesterday and the
> results are attached (I used zip to ensure verbatim transport).
> I have divided script into two, because I was not able to debugg
> your find command. However, I have now problem with bash.
> Consider following screenshot:
>
> mail $ test -f ./sluzebni/; echo $?
> 1
> mail $ test -d ./sluzebni/; echo $?
> 0
> mail $ ll
> total 332
> -rw-rw-r-- 1 matej matej 0 kvě 3 19:30 drafts
> drwxrwxr-x 2 matej matej 4096 zář 9 15:54 list
> drwxrwxr-x 2 matej matej 4096 zář 25 10:26 pratele
> -rw-rw-r-- 1 matej matej 270658 kvě 2 06:03 sent-200104
> -rw-rw-r-- 1 matej matej 45374 kvě 3 20:58 sent-200105
> drwxrwxr-x 2 matej matej 4096 zář 25 10:48 sluzebni
>
> If understand my bash manpage well, the second command should
> produce 1 too. Have you any idea why it doesn't? I am using bash
> 2.04.11(1)-release on RedHat GNU/Linux 7.0.
Why would the second produce 1?
Here is what I get, doing something similar:
bash$ echo $BASH_VERSION
2.03.8(1)-release
bash$ if test -d ./tmp/; then echo "./tmp is a directory"; fi
./tmp is a directory
bash$ test -d ./tmp; echo $?
0
Remember, under *nix, 0 is true, 1 is false, so this is the
correct behavior.
-f tests that (quoting man test): "FILE exists and is a regular
file", i.e., not a directory, thus the 1 (false) return value for
the first call to test.
If you are using shell builtins and standard commands, you can
rely on what you are used to as "truth" if you merely call test
in a boolean context:
if test -d ./sluzebni/; then
# it is a directory; do your stuff
else
# not a directory; perhaps check -f or -S?
fi
The contents of $? is probably not what you're after, so much as
a true value, unless you are checking for a specific error message.
(darren)
--
Don't sweat the petty things, and don't pet the sweaty things.