首页 > 系统服务 > 详细

How to Catch Ctrl-C in Shell Script

时间:2017-11-02 00:36:47      阅读:359      评论:0      收藏:0      [点我收藏+]
 
#!/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 2
    # if omitted, shell script will continue execution
    exit 2
}
 
# initialise trap to call trap_ctrlc function
# when signal 2 (SIGINT) is received
trap "trap_ctrlc" 2
 
# your script goes here
echo "going to sleep"
sleep 1000
echo "end of sleep"

 

How to Catch Ctrl-C in Shell Script

原文:http://www.cnblogs.com/pinganzi/p/7769107.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!