Operating System - HP-UX
1834811 Members
2811 Online
110070 Solutions
New Discussion

trap a signal and display it

 
Marc Ahrendt
Super Advisor

trap a signal and display it

below is what i want to do but not sure what should replace XXX ...if something even exists

trap "echo Exiting on a trap XXX...; sleep 2; exit 1" 0 1 2 3 4 15

where XXX would be either 0,1,2,3,4,15 based on which one of these signals comes to the shell script
hola
2 REPLIES 2
John Palmer
Honored Contributor

Re: trap a signal and display it

Hi,

One way is to use a trap handling function and provide the signal number as its argument thus:

function handle {
print "Exiting on trap ${1}"
sleep 2
exit 1
}

trap "handle 0" 0
trap "handle 1" 1
...

Regards,
John
Marc Ahrendt
Super Advisor

Re: trap a signal and display it

thx john: i like your approach better than mine, but it does not answer my main question.

from looking at the forum achives and john's response above it seems that i can only write a trap statement/line for each signal i want to trap AND display to stdout ...just wanted to reduce the script by making one trap statement
hola