Web lists-archives.com

Re: Off topic: non zero error codes




On Sun, May 19, 2019 at 05:21:38AM +0000, Erik Josefsson wrote:
> Good morning,
> 
> I have wanted to ask for a long time about something I made up from
> hearsay whether it is remotely true. I hope that's OK.
> 
> Is there is a shell/language where the returncode for TRUE is zero
> and that that is the opposite of how all other shells/languages are
> made?
> 
> The argument for creating it was that it then becomes handier to say
> "no errors, one error, two errors..." than to say "success, one
> error, two errors...".
> 
> I mean: (0, 1, 2, ...) is handier than (1, 0, whatever, ...).

Yes... and no.

What you are referring to is the UNIX convention, that programs
deliver an integer code at exit, which is typically interpreted
as "error code" -- thus zero => no error. This is a convention,
though, so programs don't have to stick to that.

The more official name is "exit code", and each civilised manual
page will have a section on these.

See f.ex. man curl(1) for one very extensive specimen.

So it won't come as a surprise that the shell, which was born to
invoke programs (and to react to their diverse (mis-)adventures)
interprets an exit code of zero as "OK", "all went well" and
so on -- while interpreting everything else as "uh-oh, perhaps
tell the user that something went wrong".

This convention mirrors the one found in the "classical" C
programming style.

Cheers
-- tomás 

Attachment: signature.asc
Description: Digital signature