views:

28

answers:

1

I am traping a signal SIGINT in one of my script I am writting for my project.

trap sigint_handler SIGINT

I am having signal handler

sigint_handler()
{
#    echo caught signal, now quiting....

     exit $?
}

So now when the script gets a CTRL+C signal it gets it and exits.

And on terminal it prints this message:

$^Killed by signal 2.
$

I know this message is generated by system. I guess this happens because of some interrupt, I may not be right.

So now I just want that somehow this message should not come on terminal when exiting the script because of that signal.

My expected behavior is that when I press CTRL+C it should not print any message and come out of the script silently as normally happens.

Can anyone tell me or suggest me to what to do to ignore this message. Is there a way to ignore this message.

Thanks.

Alok.Kr.

A: 

Where is the trap statement?

trap 'echo "signal received, exiting"' 2

would be an example trap statement to trap signal #2 - which is SIGINT (ctrl/c) on POSIX systems.

jim mcnamara
trap sigint_handler SIGINTthis is the trap for SIGINT that is signal 2.
Kumar Alok
Your function does nothing that I can see. It is what is sometimes called 'fall-through' meaning that it gets executed but nothing happens to change program state.
jim mcnamara