How to Catch Ctrl-C in Shell Script

 
#!/bin/sh

# this function is called when Ctrl-C is sent
function trap_ctrlc ()
{
# perform cleanup here
echo "Ctrl-C caught...performing clean up" echo "Doing cleanup" # exit shell script with error code
# if omitted, shell script will continue execution
exit
} # initialise trap to call trap_ctrlc function
# when signal (SIGINT) is received
trap "trap_ctrlc" # your script goes here
echo "going to sleep"
sleep
echo "end of sleep"
上一篇:如何写一个makefile


下一篇:eclipse svn插件安装方法