trap troubles
Marty Wiedmeyer
mort at dhump.lakesys.COM
Mon Aug 20 01:37:07 AEST 1990
Hi,
I've discovered that trap doesn't work the way I thought it did.
I've used it to mop up tmp files with
trap 'rm -f /tmp/nifty.script*' 0 1 2 3 15
dependably for quite a while.
Now I want to do some real work with it :-).
One of my customers has a hardware PC "elevator" card in an Apollo.
Sometimes it dies unexpectedly with an exit code of 1. He wants to
run the PC-on-a-card from an sh script and give the user some options
after the PCboard pukes, like
1) attempt to re-start the elevator
2) do nothing further if the elevator script/command exits 0.
3) if the elevator exits 1, either re-start, or ask to start
up the software emulation (dpce).
However, I have discovered that executing a script which has a non-zero
exit status and trap with commands to be executed upon that exit status
(see below), results in the trapped commands _not_ being performed. Query
of the shell immediately upon termination of the script with echo $?
shows the correct exit status.
I have read TFM (in this case "The UNIX Shell Programming Language"
Mannis/Meyer). It leads me to think it should be able to work
this way. Am I missing something?
Please email. I will try to keep up on this group, but the expire
time here is short.
Thanks!
------------------------Sample Script----------------------------
:
#
# Run this, then do
# echo $?
# at the shell!
trap 'echo "trap 2"' 2
ls
exit 2
--
Marty Wiedmeyer INTERNET: mort at dhump.lakesys.com
3473 N. Fratney St. BANG: uunet!marque!dhump!mort
Milwaukee, WI 563212 RING: (414) 963-2182
More information about the Comp.unix.questions
mailing list