linux-tutorial/codes/shell/示例脚本/控制/捕捉信号.sh

17 lines
230 B
Bash
Raw Normal View History

2019-05-10 11:17:57 +08:00
#!/bin/bash
# testing signal trapping
2019-10-10 08:56:31 +08:00
trap "echo'Sorry! I have trapped Ctrl-C'" SIGINT SIGTERM
2019-05-10 11:17:57 +08:00
echo this is a test program
count=1
while [ $count -le 10 ]
do
2019-10-10 08:56:31 +08:00
echo "Loop #$count"
sleep 5
count=$[ $count + 1 ]
2019-05-10 11:17:57 +08:00
done