emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#10390: closed (Bug with Test Command)


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#10390: closed (Bug with Test Command)
Date: Wed, 28 Dec 2011 13:31:02 +0000

Your message dated Wed, 28 Dec 2011 06:28:06 -0700
with message-id <address@hidden>
and subject line Re: bug#10390: Bug with Test Command
has caused the debbugs.gnu.org bug report #10390,
regarding Bug with Test Command
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
10390: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10390
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: Bug with Test Command Date: Wed, 28 Dec 2011 00:12:49 -0600 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

--- End Message ---
--- Begin Message --- Subject: Re: bug#10390: Bug with Test Command Date: Wed, 28 Dec 2011 06:28:06 -0700 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0
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   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]