Newsgroups: comp.unix.questions,ti.unix.tools,fj.questions.unix
Path: galaxy.trc.rwcp.or.jp!coconuts.jaist!wnoc-tyo-news!etlnews.etl.go.jp!etlinn.etl.go.jp!etl.go.jp!trc.rwcp!rwc-tyo!news.iij.ad.jp!nr1.scn.co.jp!sinfony-news!news.kddnet.ad.jp!news.dvlp.kddnet.ad.jp!news.cs.ritsumei.ac.jp!kuis-news!s2000!beauty!clair.noc.fujita-hu.ac.jp!fame.fujita-hu.ac.jp!chiba-ns!villon.nig.ac.jp!aa.com!newsbase.nisiq.net!newsfeed.internetmci.com!news.sprintlink.net!news-peer.sprintlink.net!cs.utexas.edu!news.ti.com!ief!usenet
From: Rusty Haddock <rusty@ti.com>
Subject: Re: How to Read Status Code
Sender: usenet@ief.itg.ti.com (Mr. USENET)
Message-ID: <3235AAB1.74E@ti.com>
Date: Tue, 10 Sep 1996 18:51:45 GMT
To: Kevin M Simonson 480-4180 <simonson@skopen.dseg.ti.com>
Reply-To: rusty@ti.com
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
References: <5148go$seb@sf18.dseg.ti.com>
Mime-Version: 1.0
X-Mailer: Mozilla 3.0 (WinNT; I)
Organization: Texas Instruments Software
Lines: 75
Xref: galaxy.trc.rwcp.or.jp fj.questions.unix:6078
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.questions.unix&nb=6078&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.

Kevin M Simonson 480-4180 wrote:

> 
>      I'm pretty sure I've seen references to this status code or return
> code in several other different places too.  But the thing I don't under-
> stand is how to tell what this status code is.  Does anyone know how to do
> that?  Is it different for different systems?  If so, what I use most of
> the time is a Sun.  If this is in the FAQ, could somebody tell me how I can
> get access to the FAQ?  Thanks.

Kevin,
   Generally, no, it's not different for different systems.  To tell
what the status code is (aka return code) will depend on how you're
running a given
program.  If you're programming in C, for instance, and using the
system()
function call, the status code will be that which is returned by the
system().

   On the other hand, if you're simply going interactive with a shell,
the
shell itself will determine how you "see" to the status code.  First,
run your
program and have it return an error (it's usually best if it errors out,
like
ls a non-existant directory).  In the Korn or Bourne-based shells issue
as your next(!) command:

echo $$

You cshell folks will do something like

echo $status.


Now, if you're doing some shell programming (hopefully *NOT* with the
Cshell :-)
read the shell's man page.  That man page will show you how to use that
return
code to have your shell do the kind of tricks you want.

As an example, let's say that in the Korn shell (ksh), I want to echo a
particular string if a certain user is the password file.  For that, I
can
do something like this:

#!/bin/ksh
luser=barney
if [ `grep -q $luser /etc/passwd` ]
then
echo "The sysadmin has finally added $luser to the system."
else
echo 'What is taking those people so long???'
fi

The THEN statements get executed if the result of the backquoted (`)
command
returned a non-zero value.  Naturally the else part is run if a zero
value
is returned.  NOTE!!!!!  And note well, that grep is, maybe, a tad bit
weird
in that it returns a zero if a match is found!   So, guess what? 
There's a
bug in the code above!  I'll leave it as an exercise in reading the ksh
man
page to find out how to fix it.  :->


-Rusty-

--
Rusty Haddock, KD4WLZ       Internet: rusty@ti.com     ___
Texas Instruments           MSG ID: MWH2            |\/  o\  O
POB 869305  MS 8515         Phone: (214) 575-6838   |  ( -< o O
Plano, Texas  75086         Fax:   (214) 575-4351   |/\_V_/
