trap command

dear all;
I can't under stand what does "trap" command do:
for example see below:

trap "echo; echo no interrupts >&2; sleep 3" 2 3 15 

Plz , can any body explain the action of this command?

BR

TRAP is looking for signals "2" "3" and "15" where

SIGHUP 1 Exit Hangup (see termio(7I))
SIGINT 2 Exit Interrupt (see termio(7I))
SIGTERM 15 Exit Terminated

ksh
*trap [ arg sig [ sig2...]]

If it sees any signals 2, 3 or 15 passed to your process, it will capture those and prevent them from being passed on to your process, instead it will display the echo message.

1 Like

thanks man that was helpful :b:

:), glad I was of some help. Have fun with trap :).