版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yueludanfeng/article/details/84847145
实例
#!/bin/bash
trap 'onCtrlC' INT
function onCtrlC () {
echo 'Ctrl+C is captured'
}
while true; do
echo 'I am working!'
sleep 1
done
执行上述脚本,按下Ctrl+C按键将会触发onCtrlC函数
https://www.jianshu.com/p/b81783fee7da