GNU bug report logs - #10390
Bug with Test Command

Previous Next

Package: coreutils;

Reported by: "Mathi.C" <mathiazhaganc <at> gmail.com>

Date: Wed, 28 Dec 2011 09:00:03 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 10390 in the body.
You can then email your comments to 10390 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#10390; Package coreutils. (Wed, 28 Dec 2011 09:00:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Mathi.C" <mathiazhaganc <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Wed, 28 Dec 2011 09:00:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Mathi.C" <mathiazhaganc <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: Bug with Test Command
Date: Wed, 28 Dec 2011 00:12:49 -0600
[Message part 1 (text/plain, inline)]
Hi,

I have come across a scenario where test command resulted wrong result than
expected.

Please follow the below steps to simulate the scenario.
1. Define a variable to blank/null
     export a=
2. Test the parameter with test command on file exists
     test -f $a
3. Echo the result of the last executed command
    echo $?

Result we get is "0" -success, whereas the test command (step 2) should
error with parameter expected after " test -f".

-- 
Regards,
Mathi.C
[Message part 2 (text/html, inline)]

Added tag(s) notabug. Request was from Eric Blake <eblake <at> redhat.com> to control <at> debbugs.gnu.org. (Wed, 28 Dec 2011 13:31:02 GMT) Full text and rfc822 format available.

Reply sent to Eric Blake <eblake <at> redhat.com>:
You have taken responsibility. (Wed, 28 Dec 2011 13:31:02 GMT) Full text and rfc822 format available.

Notification sent to "Mathi.C" <mathiazhaganc <at> gmail.com>:
bug acknowledged by developer. (Wed, 28 Dec 2011 13:31:02 GMT) Full text and rfc822 format available.

Message #12 received at 10390-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: "Mathi.C" <mathiazhaganc <at> gmail.com>
Cc: 10390-done <at> debbugs.gnu.org
Subject: Re: bug#10390: Bug with Test Command
Date: Wed, 28 Dec 2011 06:28:06 -0700
[Message part 1 (text/plain, inline)]
tag 10390 notabug
thanks

On 12/27/2011 11:12 PM, Mathi.C wrote:
> Hi,
> 
> I have come across a scenario where test command resulted wrong result than
> expected.
> 
> Please follow the below steps to simulate the scenario.
> 1. Define a variable to blank/null
>      export a=
> 2. Test the parameter with test command on file exists
>      test -f $a

There's your problem.  You failed to properly quote things.  Per shell
expansion rules, unquoted $a is elided, rather than an empty argument,
which means you passed test exactly one argument ("-f"), and since that
one argument is not empty, it is always true.

If you want to cope with an explicit empty string, you must use quoting:

test -f "$a"

> 3. Echo the result of the last executed command
>     echo $?

As this behavior matches POSIX requirements on test, there is nothing to
fix here.  Also, be aware that you were probably testing your shell's
built-in test, rather than coreutils' test (running the latter usually
requires that you do things like 'env test' or '/usr/bin/test' to bypass
shell built-ins).

-- 
Eric Blake   eblake <at> redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 26 Jan 2012 12:24:02 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 200 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.