Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #108240

Re: main return value is helpfull?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: main return value is helpfull?
Date 2017-04-17 12:19 -0700
Organization None to speak of
Message-ID <lninm2suzb.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>

Show all headers | View raw


Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
[...]
> Unix shell scripting languages have a well-defined behaviour wrt evaluating 
> the return value from a process.
> 1) Unless explicitly tested, the return value (no matter what it is) is
>    ignored.

There's an option (`set -e`) to terminate the script if a command fails,
but it's not set by default.

> 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 for sh-derived shells, including sh, bash, zsh, kshd.
It doesn't necessarily apply to csh, tcsh, fish, etc.)

> 3) The script may test for a specific return value, and take action
>    accordingly.

Yes.

[...]

-- 
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


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