It is currently Tue, 30 Nov 2021 18:16:36 GMT



 
Author Message
 sh: trap 0 and exit status
I got bitten by this lately. On a Sun running Solaris 2.3,
it seems that if you do "trap cmd 0", and then "exit 1",
"cmd" is executed as you'd expect, but the shell exits with
status 0, not with status 1 as requested. No problem - I can
work around it by calling a function instead of calling exit
directly, and having the function store the status in a global
variable. But I did wonder whether exiting with status 0
is The Right Thing, or whether Sun's sh is broken...

steve
--
<Steve_Kilb...@cegelecproj.co.uk>
GCS d--(---)-p+ c++(+++)l(+)u++++e++(-)m---s+/-n-@h+(---)f+(++)!g(+)w+tr@y+
#include <std_disclaimer.h>........"Duh da duh de duh da duh" -Angus Young.



 Tue, 09 Sep 1997 19:55:59 GMT   
 sh: trap 0 and exit status
In article <3kuc0f$...@jupiter.sdd.cegelecproj.co.uk>, st...@spirit.cegelecproj.co.uk (Steve_Kilbane) writes:
|> I got bitten by this lately. On a Sun running Solaris 2.3,
|> it seems that if you do "trap cmd 0", and then "exit 1",
|> "cmd" is executed as you'd expect, but the shell exits with
|> status 0, not with status 1 as requested. No problem - I can
|> work around it by calling a function instead of calling exit
|> directly, and having the function store the status in a global
|> variable. But I did wonder whether exiting with status 0

I tried this out with the Bourne Shell and the pd-ksh (V. 5.1.2),
and realized that the shell exits with the exit code your
command "cmd" returns.

You may change your script or function "cmd" to return
the exit status you want.

Heiner
--

      -------------------------------------------------------------
     / Heiner Steven  h...@bintec.de / The expressed opinions are  /
    / BinTec Computersysteme GmbH / mine, not BinTec's --       /
   / Willstaetter Str. 30 -------   ...even if they should ;-) /
  / D-90449 Nuernberg    /                                    /
 / (049) 0911/9673-0    / priv.: hei...@hsysnbg.nbg.sub.org  /
-------------------------------------------------------------



 Sat, 13 Sep 1997 03:00:00 GMT   
 sh: trap 0 and exit status
In <3kuc0f$...@jupiter.sdd.cegelecproj.co.uk> st...@spirit.cegelecproj.co.uk

Actually, I think you'll find that the shell exits with the exit status
from "cmd", whatever that is.



 Sat, 13 Sep 1997 08:38:02 GMT   
 sh: trap 0 and exit status

Well, yes, that's the problem. Since "cmd" is usually a clean-up, it's
often something like "rm -rf tmpdir", and so it's going to succeed
whatever. This part is The Right Thing, but I think that the shell should
have set $? before invoking "cmd", so that "cmd" can pass the value
from exit back the calling process.

steve
--
<Steve_Kilb...@cegelecproj.co.uk>
GCS d--(---)-p+ c++(+++)l(+)u++++e++(-)m---s+/-n-@h+(---)f+(++)!g(+)w+tr@y+
#include <std_disclaimer.h>........"Duh da duh de duh da duh" -Angus Young.



 Sat, 13 Sep 1997 16:28:16 GMT   
 
   [ 4 post ] 

Similar Threads

1. Exit status in trapped exit function

2. trap and exit status

3. exit status inside trap

4. exit status of pipeline in sh/csh

5. subprocess exits with status 2, and sh script stops

6. Exit status in /bin/sh

7. Getting exit status from backgrounded job in sh

8. Exit status, $?, and term status

9. Exit nn via trap Q


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