Subject: bug#24894: closed (Re: bug#24894: coreutils 8.4 : `test -s` without argument does not return an error)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 07 Nov 2016 16:47:03 +0000

Your bug report

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

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
24894: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=24894
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#24894: coreutils 8.4 : `test -s` without argument does not return an error
From: Eric Blake <[email-masked]>
To: BAECKEROOT Alain <[email-masked]>, [email-masked]
Date: Mon, 7 Nov 2016 10:46:16 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

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@cms054:/i/w/l/w00/was> echo $SHELL
> /bin/ksh
> wasoi@cms054:/i/w/l/w00/was> uname
> AIX
> wasoi@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@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

Subject: coreutils 8.4 : `test -s` without argument does not return an error
From: BAECKEROOT Alain <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Mon, 7 Nov 2016 12:58:15 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

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@CMV03:/home/wasoi> echo $SHELL
/bin/ksh
wasoi@CMV03:/home/wasoi> uname
Linux
wasoi@CMV03:/home/wasoi> test -s
wasoi@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@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@cms054:/i/w/l/w00/was> echo $SHELL
/bin/ksh
wasoi@cms054:/i/w/l/w00/was> uname
AIX
wasoi@cms054:/i/w/l/w00/was> test -s
ksh: test: argument expected
wasoi@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)

*****************************************************************************************

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.