testing exit status

testing exit status

Post by Kathy Lyon » Mon, 29 Sep 1997 04:00:00



I have a simple question...

I have a child shell that is running a short program. If it exits ok, I
return a 0. If it receives a kill message, I abort with a 1.  How do I test
for this condition in the parent shell???  Right now I am doing the
following in the parent shell:

        If true
        then
                echo processing ok
        else
                echo processing not ok

This does not seem to be working.  Any ideas???  Thanks.  Respond here or

 
 
 

testing exit status

Post by Antonio Quenta » Tue, 30 Sep 1997 04:00:00




Quote:> I have a simple question...

> I have a child shell that is running a short program. If it exits ok, I
> return a 0. If it receives a kill message, I abort with a 1.  How do I
test
> for this condition in the parent shell???  Right now I am doing the
> following in the parent shell:

>    If true
>    then
>            echo processing ok
>    else
>            echo processing not ok

if you are running a program inside your shell script, you can test it's
return code in this way:

#your script starts here
...
your_short_program
if [ $? -eq 0 ]
then
        echo program exited OK
else
        echo program aborted
fi

or you don't want to use the IF clase, chain commands like this :
        if true :
$ command && { comand1; comand2; ....}
   if command returns true, execute the rest
        if false:
$ command || { comand1; comand2; ....}
   if command returns false, execute the rest

        Hope it helps !
                        Quental

 
 
 

testing exit status

Post by Bill Marc » Tue, 30 Sep 1997 04:00:00




Quote:>I have a simple question...

>I have a child shell that is running a short program. If it exits ok, I
>return a 0. If it receives a kill message, I abort with a 1.  How do I test
>for this condition in the parent shell???  Right now I am doing the
>following in the parent shell:

>    If true
>    then
>            echo processing ok
>    else
>            echo processing not ok

"true" is a Unix command (either a builtin shell command or /bin/true) which
always returns a true (0) status.  If your child script is named "true",
I would recommend changing it.  Otherwise, you could do:

if your_child
then
        echo processing ok
else
        echo processing not ok
fi

>This does not seem to be working.  Any ideas???  Thanks.  Respond here or


--
Bill Marcum
"Well, actually, the Internet has been cream-filled for years" (Over the Hedge)
 
 
 

testing exit status

Post by Pete » Tue, 30 Sep 1997 04:00:00


Try:

echo $?

in the parent shell



> I have a simple question...

> I have a child shell that is running a short program. If it exits ok, I
> return a 0. If it receives a kill message, I abort with a 1.  How do I
test
> for this condition in the parent shell???  Right now I am doing the
> following in the parent shell:

>    If true
>    then
>            echo processing ok
>    else
>            echo processing not ok

> This does not seem to be working.  Any ideas???  Thanks.  Respond here or


 
 
 

testing exit status

Post by Icarus Spar » Thu, 02 Oct 1997 04:00:00






>> I have a simple question...

>> I have a child shell that is running a short program. If it exits ok, I
>> return a 0. If it receives a kill message, I abort with a 1.  How do I
>test
>> for this condition in the parent shell???  Right now I am doing the
>> following in the parent shell:
>#your script starts here
>...
>your_short_program
>if [ $? -eq 0 ]
>then
>    echo program exited OK
>else
>    echo program aborted
>fi

Why not just use the more obvious

        if your_short_program
        then
                echo program exited OK
        else
                echo program aborted
        fi

Testing $? is works, and is a good idea if the command to test is a long
one, but for short commands, the syntax above is more readable.

 
 
 

testing exit status

Post by Eric Kleinber » Sat, 04 Oct 1997 04:00:00


If I understand you correctly..you should query the shell variable "$?"
which is set to the exit
status of a command. The child shell should do something like:

        myprogram
        exit $?



> I have a simple question...

> I have a child shell that is running a short program. If it exits ok, I
> return a 0. If it receives a kill message, I abort with a 1.  How do I
test
> for this condition in the parent shell???  Right now I am doing the
> following in the parent shell:

>    If true
>    then
>            echo processing ok
>    else
>            echo processing not ok

> This does not seem to be working.  Any ideas???  Thanks.  Respond here or


 
 
 

1. Test exit status of command prior to last command

Running Redhat Linux 6.2
Bash-2.04

The subject line is kind of a mouthful, but here is what I'm after.

Imagine you want to test the exit status of a command but you also
want the results of the command, including any errors, piped through
`tee' to screen and a file.

  command 2>&1|tee FILE

Now imagine further that you need to test the exit status of
`command' for further processing..

If you use the normal test, that is, if your script reads like this:

   command 2>&1|tee FILE

   if [ $? != 0 ];then
       do something
   fi

The test you've run is against the tee command not the targeted `command'.
So how can one test `command' exit status in the above setup, short
of just dropping the `tee' part?

2. i DIDN'T BELIVE BUT IT WORKS!

3. Testing for nonzero exit status with style.

4. O(1) scheduler seems to lock up on sched_FIFO and sched_RR ta sks

5. testing a commands exit status

6. XFree86 3.3

7. Exit status in trapped exit function

8. /dev/ttyp1: Operation not permitted

9. Exit status, $?, and term status

10. should xargs exit on non-zero program exit status?

11. test test test test test test test

12. PANIC: exit - Cannot exec /etc/init (PID 1), status 0x00000200

13. Returning exit status