Linux -trap

Trap 

The trap command allows you to execute a command when a signal is received by your script. It works like this:

trap arg signals

note: signals is a list of signals to intercept and "arg" is a command to execute when one of the signals is received. 

trap 命令,用来相应信号。其命令格式如下:

trap "command or commands" signal-numbers(or names)

note:命令或者命令组应该放在双引号内,多个命令用分号隔开,多个信号之间用空格分开

 

trap的三种形式

(1) 如果trap中命令丢失,表示脚本接受信号的默认动作

(2)如果捕获信号的命令参数是空字符串,表示脚本需要忽略这些信号。例如 trap "" 2 3 表示信号2,3将被忽略

(3)如果捕获信号的命令参数包含一个或者一组命令,表示脚本需要捕获信号,并在信号采取自己的动作之前保存一段时间一遍完成某些动作。

如:

trap "cp ~/file1 /root/" 2 3 15

待续。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值