coreutils
[Top][All Lists]
Advanced

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

Re: true,false: --version,--help exit code


From: Pádraig Brady
Subject: Re: true,false: --version,--help exit code
Date: Tue, 03 Jun 2014 10:56:20 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

On 06/03/2014 08:50 AM, Bernhard Voelker wrote:
> Q: Why does 'true --help >/dev/full' return 1?
> 
> Longer story:
> I was wondering why 'false --version' exits with 1, so looking
> up the POSIX specification [0] made it clear:
> 
>   The false utility shall always exit with a value other than zero.
> 
> So I looked at src/true.c and found the atexit handler detecting
> write errors [1, line 67]:
> 
>       atexit (close_stdout);
> 
> ... despite true's spec [2] which is quite clear about the exit code, too:
> 
>   The true utility shall return with exit code zero.
> 
> This looks like a (well, little) contradiction to me: the options
> --help and --version are GNU extensions and therefore may or may
> not lead to a different exit code than specified for the normal
> operation of the tool, but I'd expect behaving them the same for
> all utilities (under all circumstances): either let 'false --version'
> return 0 (because the GNU extension operation succeeded), or let
> 'true --version >/dev/full' return 0 (because POSIX says that 'true'
> should always return 0).
> WDYT?
> 
> [0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/false.html
> [1] 
> http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/true.c?id=1239ac573d#n67
> [2] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/true.html

Heh I never thought I'd be discussing the logic in true/false :)

There is an inconsistency here with the (GNU) options.
Now I don't think anyone would ever be using `env true --version > blah`
in a script, but it would be better to be consistent here
and have the exit code dependent on the name rather than the environment.

I also see that the test script for `false` was only
checking the shell builtin :/

The attached fixes up both issues in your name.
OK to push?

thanks,
Pádraig.



Attachment: true-false.patch
Description: Text Data


reply via email to

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