GNU bug report logs - #24894
coreutils 8.4 : `test -s` without argument does not return an error

Previous Next

Package: coreutils;

Reported by: BAECKEROOT Alain <alain.baeckeroot <at> carsat-sudest.fr>

Date: Mon, 7 Nov 2016 16:34:01 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 24894 in the body.
You can then email your comments to 24894 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#24894; Package coreutils. (Mon, 07 Nov 2016 16:34:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to BAECKEROOT Alain <alain.baeckeroot <at> carsat-sudest.fr>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 07 Nov 2016 16:34:02 GMT) Full text and rfc822 format available.

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

From: BAECKEROOT Alain <alain.baeckeroot <at> carsat-sudest.fr>
To: "bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>
Subject: coreutils 8.4 :  `test -s`  without argument does not return an error 
Date: Mon, 7 Nov 2016 12:58:15 +0000
[Message part 1 (text/plain, inline)]
Dear gnu-coreutils team

We had a funny problem caused by `test` which does return "0" when an option is given without any EXPRESSION 

The man page says (near line 15 or so) : 
      An  omitted  EXPRESSION defaults to false.

This is not the case when an option is given (tested for -s and -d options)

wasoi <at> CMV03:/home/wasoi> echo $SHELL
/bin/ksh
wasoi <at> CMV03:/home/wasoi> uname
Linux
wasoi <at> CMV03:/home/wasoi> test -s
wasoi <at> CMV03:/home/wasoi> echo $?
0

I expected an error (at least return code not zero) , or it would be nice to be warned in the man page.

----------
system and package information : 
	wasoi <at> CMV03:/home/wasoi> cat /etc/redhat\-release
	CentOS release 6.4 (Final)

List of rpm
	coreutils-libs-8.4-19.el6.x86_64
	coreutils-8.4-19.el6.x86_64
	policycoreutils-2.0.83-19.30.el6.x86_64

-------------
reference : On *AIX* 6.1 , with IBM's test , there is an error 

wasoi <at> cms054:/i/w/l/w00/was> echo $SHELL
/bin/ksh
wasoi <at> cms054:/i/w/l/w00/was> uname
AIX
wasoi <at> cms054:/i/w/l/w00/was> test -s
ksh: test: argument expected
wasoi <at> cms054:/i/w/l/w00/was> echo $?
1

This was the expected behavior :-)  

The *AIX* man page gives 
Exit Status

       This command returns the following exit values:
       Item
            Description
       0
            The Expression parameter is true.
       1
            The Expression parameter is false or missing.
       >1
            An error occurred.

-------------

Best regards , and thanks a lot for your work.

Alain BAECKEROOT (cnav.fr)

[Message part 2 (text/plain, inline)]
*****************************************************************************************


Ce message électronique, les éventuels fichiers joints et les informations qu'il contient, peuvent être couverts par le secret professionnel et sont exclusivement adressés à son destinataire. Si vous le recevez par erreur, merci d'en informer l'expéditeur et de le détruire. A ce titre, toute diffusion non autorisée de ce message, même partielle, sous quelque forme que ce soit, est interdite et punie par la loi.

En aucun cas, le contenu de ce message ne peut valoir offre ou acceptation ou engagement de la part de la CARSAT SUD-EST.

Les opinions contenues dans ce message sont personnelles à l'émetteur.

Il est de la responsabilité du destinataire de s'assurer que le message et ses éventuelles pièces jointes ne contiennent pas de virus informatique.
[Message part 3 (text/html, inline)]

Added tag(s) notabug. Request was from Eric Blake <eblake <at> redhat.com> to control <at> debbugs.gnu.org. (Mon, 07 Nov 2016 16:47:02 GMT) Full text and rfc822 format available.

Reply sent to Eric Blake <eblake <at> redhat.com>:
You have taken responsibility. (Mon, 07 Nov 2016 16:47:03 GMT) Full text and rfc822 format available.

Notification sent to BAECKEROOT Alain <alain.baeckeroot <at> carsat-sudest.fr>:
bug acknowledged by developer. (Mon, 07 Nov 2016 16:47:03 GMT) Full text and rfc822 format available.

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

From: Eric Blake <eblake <at> redhat.com>
To: BAECKEROOT Alain <alain.baeckeroot <at> carsat-sudest.fr>,
 24894-done <at> debbugs.gnu.org
Subject: Re: bug#24894: coreutils 8.4 : `test -s` without argument does not
 return an error
Date: Mon, 7 Nov 2016 10:46:16 -0600
[Message part 1 (text/plain, inline)]
tag 24894 notabug
thanks

On 11/07/2016 06:58 AM, BAECKEROOT Alain wrote:
> Dear gnu-coreutils team
> 
> We had a funny problem caused by `test` which does return "0" when an option is given without any EXPRESSION 
> 
> The man page says (near line 15 or so) : 
>       An  omitted  EXPRESSION defaults to false.

You are correct that it states that, but it means that 'test' (with no
expression at all) is what results in a false return (that is, an
omitted expression is equivalent to zero arguments).  'test -s' is NOT a
case of an omitted expression; your expression was '-s'.  Since you
provided exactly one argument, you are testing whether '-s' is the empty
string (it is not, hence the true result).

The full POSIX rules are here:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

> I expected an error (at least return code not zero) , or it would be nice to be warned in the man page.

You are correct that the man page could probably do a bit better at
explaining that test's behavior is STRONGLY influenced by the number of
parameters present (and this is per POSIX rules, so it is not just
coreutils' test implementation, but ALL conforming implementations that
will behave the same way).

> -------------
> reference : On *AIX* 6.1 , with IBM's test , there is an error 
> 
> wasoi <at> cms054:/i/w/l/w00/was> echo $SHELL
> /bin/ksh
> wasoi <at> cms054:/i/w/l/w00/was> uname
> AIX
> wasoi <at> cms054:/i/w/l/w00/was> test -s
> ksh: test: argument expected

That is a bug in AIX's ksh, which is not POSIX compliant.

> wasoi <at> cms054:/i/w/l/w00/was> echo $?
> 1
> 
> This was the expected behavior :-)  

Sorry, but that behavior is contrary to POSIX.

> Ce message électronique, les éventuels fichiers joints et les informations qu'il contient,

Legalese like this is unenforceable on public mailing lists; you may
wish to use a personal email account rather than spamming us with your
employer's garbage disclaimer.

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

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

Information forwarded to bug-coreutils <at> gnu.org:
bug#24894; Package coreutils. (Mon, 07 Nov 2016 16:52:02 GMT) Full text and rfc822 format available.

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

From: Pádraig Brady <P <at> draigBrady.com>
To: BAECKEROOT Alain <alain.baeckeroot <at> carsat-sudest.fr>, 24894 <at> debbugs.gnu.org
Subject: Re: bug#24894: coreutils 8.4 : `test -s` without argument does not
 return an error
Date: Mon, 7 Nov 2016 16:51:33 +0000
On 07/11/16 12:58, BAECKEROOT Alain wrote:
> Dear gnu-coreutils team
> 
> We had a funny problem caused by `test` which does return "0" when an option is given without any EXPRESSION 
> 
> The man page says (near line 15 or so) : 
>       An  omitted  EXPRESSION defaults to false.

It's a bit of a gotcha, but not a bug. I updated:
http://www.pixelbeat.org/docs/coreutils-gotchas.html#test

thanks,
Pádraig




Information forwarded to bug-coreutils <at> gnu.org:
bug#24894; Package coreutils. (Mon, 07 Nov 2016 16:57:01 GMT) Full text and rfc822 format available.

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

From: Reuti <reuti <at> staff.uni-marburg.de>
To: Eric Blake <eblake <at> redhat.com>
Cc: 24894-done <at> debbugs.gnu.org,
 BAECKEROOT Alain <alain.baeckeroot <at> carsat-sudest.fr>
Subject: Re: bug#24894: coreutils 8.4 : `test -s` without argument does not
 return an error
Date: Mon, 7 Nov 2016 17:56:08 +0100
[Message part 1 (text/plain, inline)]
> Am 07.11.2016 um 17:46 schrieb Eric Blake <eblake <at> redhat.com>:
> 
> tag 24894 notabug
> thanks
> 
> On 11/07/2016 06:58 AM, BAECKEROOT Alain wrote:
>> Dear gnu-coreutils team
>> 
>> We had a funny problem caused by `test` which does return "0" when an option is given without any EXPRESSION
>> 
>> The man page says (near line 15 or so) :
>>      An  omitted  EXPRESSION defaults to false.
> 
> You are correct that it states that, but it means that 'test' (with no
> expression at all) is what results in a false return (that is, an
> omitted expression is equivalent to zero arguments).  'test -s' is NOT a
> case of an omitted expression; your expression was '-s'.  Since you
> provided exactly one argument, you are testing whether '-s' is the empty
> string (it is not, hence the true result).

Doesn't -s refer to a FILE existence, it's not -z?

But I thought in a similar way: it may be incomplete, but not omitted.

Nevertheless: the bash builtin behaves the same.

@Alain: I have no AIX, but l get the impression that test is also a ksh-builtin. Are you getting the results for both implementations?

-- Reuti


> The full POSIX rules are here:
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
> 
>> I expected an error (at least return code not zero) , or it would be nice to be warned in the man page.
> 
> You are correct that the man page could probably do a bit better at
> explaining that test's behavior is STRONGLY influenced by the number of
> parameters present (and this is per POSIX rules, so it is not just
> coreutils' test implementation, but ALL conforming implementations that
> will behave the same way).
> 
>> -------------
>> reference : On *AIX* 6.1 , with IBM's test , there is an error
>> 
>> wasoi <at> cms054:/i/w/l/w00/was> echo $SHELL
>> /bin/ksh
>> wasoi <at> cms054:/i/w/l/w00/was> uname
>> AIX
>> wasoi <at> cms054:/i/w/l/w00/was> test -s
>> ksh: test: argument expected
> 
> That is a bug in AIX's ksh, which is not POSIX compliant.
> 
>> wasoi <at> cms054:/i/w/l/w00/was> echo $?
>> 1
>> 
>> This was the expected behavior :-)
> 
> Sorry, but that behavior is contrary to POSIX.
> 
>> Ce message électronique, les éventuels fichiers joints et les informations qu'il contient,
> 
> Legalese like this is unenforceable on public mailing lists; you may
> wish to use a personal email account rather than spamming us with your
> employer's garbage disclaimer.
> 
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
> 

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

Information forwarded to bug-coreutils <at> gnu.org:
bug#24894; Package coreutils. (Mon, 07 Nov 2016 17:01:01 GMT) Full text and rfc822 format available.

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

From: Eric Blake <eblake <at> redhat.com>
To: Reuti <reuti <at> staff.uni-marburg.de>
Cc: 24894-done <at> debbugs.gnu.org,
 BAECKEROOT Alain <alain.baeckeroot <at> carsat-sudest.fr>
Subject: Re: bug#24894: coreutils 8.4 : `test -s` without argument does not
 return an error
Date: Mon, 7 Nov 2016 11:00:29 -0600
[Message part 1 (text/plain, inline)]
On 11/07/2016 10:56 AM, Reuti wrote:
>> You are correct that it states that, but it means that 'test' (with no
>> expression at all) is what results in a false return (that is, an
>> omitted expression is equivalent to zero arguments).  'test -s' is NOT a
>> case of an omitted expression; your expression was '-s'.  Since you
>> provided exactly one argument, you are testing whether '-s' is the empty
>> string (it is not, hence the true result).
> 
> Doesn't -s refer to a FILE existence, it's not -z?

When there are TWO arguments, '-s "$file"' tests for whether file is
empty, and '-z "$string"' tests for whether $string is empty.  But here
we are talking about ONE argument, '-s', which is non-empty.  (Yes, the
one-argument case is identical to using the two-argument -z "$string" case.)

-- 
Eric Blake   eblake 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. (Tue, 06 Dec 2016 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 8 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.