Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #108279
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: main return value is helpfull? |
| Date | 2017-04-18 09:29 -0700 |
| Organization | None to speak of |
| Message-ID | <ln37d5smq3.fsf@kst-u.example.com> (permalink) |
| References | <7e8ec0c1-c5ac-4657-8c7f-5c26c5bf0c74@googlegroups.com> <a9769738-bba6-4f5a-92c5-d7050edfa5d6@googlegroups.com> <od2vg1$m5o$1@dont-email.me> <lninm2suzb.fsf@kst-u.example.com> <od4rpv$18hq$1@gioia.aioe.org> |
Manfred <noname@invalid.add> writes:
> On 04/17/2017 09:19 PM, Keith Thompson wrote:
>>> 2) When explicitly tested, a return value of zero (0) is treated as an
>>> indication of success. A non-zero value is/not/ an explicit indication
>>> of failure.
>> It depends on how you test it. For example, the shell's "if" statement
>> treats a return value of 0 as success/true, and any non-zero return
>> value as failure/false.
> This is probably best expressed as the shell, when converting to
> boolean, mapping zero to true, and nonzero to false. The notion of
> success/failure might suggest consequences that are in fact left under
> control of the script writer.
The way I'd describe it is that the shell's "if" statement (unlike
C's "if" statement) makes its decision based on whether the command
succeeds or fails rather than truth vs. falsehood.
That's why there's a "true" command that always succeeds,and a
"false" command that always fails, along with a "test" command that
evaluates an expression and then succeeds if it's true or fails
if it's false. If you have a true/false condition, you have to
convert it to a success/failure status in order to use it with "if".
The shell's use of zero for success and any non-zero value for
failure can be a little confusing, since it's seemingly the opposite
of C's use of zero for false and non-zero for true. The reason
is that typically there's only one way for a command to succeed,
and multiple ways it can fail.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
main return value is helpfull? esmaeel ensanimehr <eensanimehr@gmail.com> - 2017-04-16 12:51 -0700
Re: main return value is helpfull? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-16 21:11 +0100
Re: main return value is helpfull? supercat@casperkitty.com - 2017-04-16 13:19 -0700
Re: main return value is helpfull? Keith Thompson <kst-u@mib.org> - 2017-04-16 14:41 -0700
Re: main return value is helpfull? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-04-16 18:58 -0700
Re: main return value is helpfull? Manfred <noname@invalid.add> - 2017-04-17 19:34 +0200
Re: main return value is helpfull? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-04-17 13:57 -0400
Re: main return value is helpfull? Keith Thompson <kst-u@mib.org> - 2017-04-17 12:19 -0700
Re: main return value is helpfull? Manfred <noname@invalid.add> - 2017-04-18 13:03 +0200
Re: main return value is helpfull? Keith Thompson <kst-u@mib.org> - 2017-04-18 09:29 -0700
Re: main return value is helpfull? gordonb.xo0e7@burditt.org (Gordon Burditt) - 2017-04-17 04:40 -0500
Re: main return value is helpfull? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-04-18 21:39 -0600
csiph-web