本文共 841 字,大约阅读时间需要 2 分钟。
trap 信号捕捉
trap用法:trap 'echo ' signal
trap 'echo "haha I am still here"' INT 当按下ctrl+c的时候会出现脚本的定义输出的信息 trap 'echo "quit the script";exit 1' INT trap 'unset var1 var2;echo "haha I am still here"' INT 创建文件夹,当捕捉到信号删除创建的文件夹,然后输出信息 trap 'rm /tmp/traptest &>/dev/null;echo "haha I am still here"' INT rm -rvf /tmp/traptest &>/dev/null echo "quid the script..." trap ‘echo "Quit..."; exit 1' SIG
ping -c1 -W1 192.168.0.$i &>/dev/null [ $? -eq 0 ] echo "this station is online" || echo "this is offline"
执行脚本,当按下ctrl+c ping就立即结束! 本文转自 张玉坡 51CTO博客,原文链接:http://blog.51cto.com/fighter/469902 转载地址:http://qsypl.baihongyu.com/