It is currently Tue, 17 May 2022 18:49:25 GMT



 
Author Message
 Catching Return Codes
I need to catch the return from several shells, some will return 0, some 1,
others 999.  Do I execute each shell and in the line following the shell put
the if  statements with $? = 0, or $? = 1, or $? = 999, will that catch the
returns ???

Thanks

George



 Wed, 04 Jun 2003 15:47:52 GMT   
 Catching Return Codes

I suppose that should work, but you might prefer a case instead:

#!/bin/bash

test_return_val() {
  case $? in
    0)   echo "Result: 0" ;;
    1)   echo "Result: 1" ;;
    999) echo "Result: 999" ;;
    *)   echo "Result: $? -- bug?" ;;
  esac

run_prog_one
test_return_val
run_prog_two
test_return_val
run_prog_n
test_return_val

Is that what you wanted?
MagicTux

--



 Wed, 04 Jun 2003 22:21:46 GMT   
 Catching Return Codes
Hi,

Could you show me an example where a shell returns 999?

From the bash man page:

EXIT STATUS
       For  the  shell's  purposes,  a command which exits with a
       zero exit status has succeeded.  An exit  status  of  zero
       indicates success.  A non-zero exit status indicates fail-
       ure.  When a command terminates on a  fatal  signal,  bash
       uses the value of 128+signal as the exit status.

       [............]

I can't imagine having more then 127 signals so the maximum return
value is 255. exit n will be handled as exit n modulo 256 so if you
write exit 999 you'll get 231 (999-3*256).

You can do:
if [ $? -eq 0 ]; then
   do_something
fi

Hope I understood what your problem is, maybe not, anyways
Best regards,
Roberto Nibali, ratz

--
mailto: `echo NrOa...@tPacA.cMh | sed 's/[NOSPAM]//g'`



 Thu, 05 Jun 2003 20:23:02 GMT   
 
   [ 3 post ] 

Similar Threads

1. How do I catch a return code?

2. Help: Returning a return code to a program

3. Help: Returning a return code to a program

4. Return Code or Error Code with patches

5. Returning an exit code with the PID as an exit code

6. help: preserving error return codes thru function codes

7. What is meant by (a signal is caught and returns)

8. How to catch the return value in sh ?

9. catching return values from processes in the background

10. How to catch error returned from shell function


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software