Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shell script Q



You can check $? in bash so something like

command_with_return_your_interested_in
if [ $? -eq 101 ] ; then
	blahhh
fi

Remember to read $? right after running the command though as it
is always the last command executed. If you will have multiple
if statements it is better to capture the value first with
a variable... something like ret=$?

Cheers,

Tom.

On Wed, Aug 09, 2000 at 11:36:14AM +0900, Frank BENNETT wrote:
> We have some APC power supplies here, and I want our Linux servers
> to take advantage of them.  I fetched the upsd package, which looks
> like it will do the trick.  The upsd daemon accepts an option that
> causes it to exit immediately with a return status that indicates
> what it deduced from the serial line it was pointed at -- power low,
> no cable found, etc.
> 
> So, I thought, all I need to do is catch the return value, run it
> through a case statement, and I'm ready to set things up.
> 
> But, uh, then I realized that I don't know how to catch a return value (as
> opposed to standard output).  The only shell operators I know of that handle
> return values are && and ||, and these are not going to help me distinguish
> between return values of 100 and 101.
> 
> I know there's a way to do this, but I have been through the Bash man page
> and I can't figure it out.
> 
> Can anyone help?
> 
> Thanks in advance,
> ----
> -x80
> Frank G Bennett, Jr         @@
> Faculty of Law, Nagoya Univ () email: bennett@example.com
> Tel: +81[(0)52]789-2239     ()
> 
> -----------------------------------------------------------------------
> Next Nomikai Meeting: August 18 (Fri) 19:00  Place: TBD
> Next Technical Meeting: September 9 (Sat) 13:30  Place: LinuxProbe Hall
> -----------------------------------------------------------------------
> more info: http://www.tlug.gr.jp           Sponsor: Global Online Japan
> 


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links