This is the expected behavior. The default signal sent by kill is SIGTERM , which you capture with your trap. Consider this:
#!/bin/bash # traptest.sh trap "echo Booh!" SIGINT SIGTERM echo "pid is $$" while : # This is the same as "while true". do a=1 done
(sleep does create a new process, and the behavior is clearer with my example, I think).
So, if you run traptest.sh in one terminal and kill TRAPTEST_PROCESS_ID from another terminal, the output in the terminal where traptest is Booh! will be Booh! as expected (and the process will NOT be killed) If you try to send kill -s HUP TRAPTEST_PROCESS_ID , it will kill the traptest process.
This should eliminate the confusion of %1 .
Note: sample code is taken from tldp
davak
source share