Ok... Sorry for disturbing you with "well documented bug", I didn't get into
"info coreutils"...

I know how are some guys anxious about POSIX compliancy, so I will keep this
feature in mind...

Btw: Perhaps some bigger warning in manpage won't be bad idea

Thanks for your time
Jakub Lucký



2010/2/7 Bob Proulx <[email protected]>

> 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
>

Reply via email to