Jakub Lucký wrote:
> Hi, I am using test in my maildrop filters and I was furious about this
>
> ja...@gondolin:~$ /usr/bin/test -f/some/nonexistent/file || echo "returned
> false"
> ja...@gondolin:~$ /usr/bin/test -f /some/nonexistent/file || echo "returned
> false"
> returned false
I am sorry that you were furious about it but that is expected behavior.
> I hope given example is self-explaining
>
> I think there are two methods to solve this:
> 1) test -f/filename returns bad option and dies
> 2) test -f/filename will be accepted and solved correctly
>
> Same bug reproducible on both stable (6.10-6) and unstable...
The problem is that you joined the "/some/nonistent/file" argument up
against the -f option. In most programs that would cause you to have
an error because all of the following characters would be seen as
options and would almost certainly generate option processing errors.
But 'test' is special. Test must remain compatible with traditional
usage. This has been standardized by POSIX and 'test' is required to
behave as it does. This is documented in the 'test' manual page.
$ info coreutils 'test invocation'
If EXPRESSION is omitted, `test' returns false. If EXPRESSION is a
single argument, `test' returns false if the argument is null and true
otherwise. The argument can be any string, including strings like
`-d', `-1', `--', `--help', and `--version' that most other programs
would treat as options. To get help and version information, invoke
the commands `[ --help' and `[ --version', without the usual closing
brackets.
'test' is special and counts the number of arguments to it. Since you
have exactly one argument "-f/some/nonexistent/file" then it returns
true with an exit code of 0. This is not a bug. This is required and
documented behavior. The standards page docmenting the requirements
is here:
http://www.opengroup.org/onlinepubs/009695399/utilities/test.html
Bob
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]