🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1205

Re: Accessing a "c" program value from a csh script

#1205
From: King Ables
Date: Fri, 21 Sep 1990 18:21
40 lines
2256 bytes
From article <2629@uc.msc.umn.edu>, by wes@uh.msc.umn.edu (Wes Barris):
> I have a "c" program that returns an integer value.  How does one run this
> program from within a csh script and access the returned value?  I have

You have two problems.

> set intro_data = "data"
> @ nobjs = `"$WF_DIR/lbin/read_intro $intro_data"`
> 
> When run, this script yields the following error message on a Sun4-280:
> 
> /usr/local/wave/lbin/read_intro data: Command not found.

Problem number 1:  If you put the command AND the arguments inside
of quotes, then the shell that gets started looks at it as a single token
(so it's looking for a command containing a space, which of course, it
doesn't find).  You don't have to quote the command inside of the grave
accents (`).

Problem number 2: Grave accents isn't what you want anyway.  That will
store the OUTPUT of the command in the symbol nobjs, not the exit status.
The exit status can be found in the $status symbol.

So if your program doesn't generate any output that would confuse the
user running the script, you should do something like this:

	set intro_data = "data"
	$WF_DIR/lbin/read_intro $intro_data
	set nobjs = $status

THEN nobjs will contain the return code.  Take care that you use $status
*right after* you run the command.  The value changes when the next command
is executed.  $status always contains the exit status of the most recently
executed command.
-----------------------------------------------------------------------------
King Ables                    Micro Electronics and Computer Technology Corp.
ables@mcc.com                 3500 W. Balcones Center Drive
+1 512 338 3749               Austin, TX  78759
-----------------------------------------------------------------------------
We don't inherit the Earth from our parents, we borrow it from our children.
Technical Details
Message-ID: <1172@lot.ACA.MCC.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!milano!cadillac!lot!ables
References: <2629@uc.msc.umn.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!milano!cadillac!lot!ables
From: ables@lot.ACA.MCC.COM (King Ables)
Newsgroups: comp.unix.shell
Subject: Re: Accessing a "c" program value from a csh script
Message-ID: <1172@lot.ACA.MCC.COM>
Date: 21 Sep 90 18:21:52 GMT
References: <2629@uc.msc.umn.edu>
Organization: MCC ACT Program, Austin, TX
Lines: 40