是否有可能发现在bash * *哪些陷阱信号? [英] Is it possible to detect *which* trap signal in bash?

查看:136
本文介绍了是否有可能发现在bash * *哪些陷阱信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/9256644/identifying-received-signal-name-in-bash-shell-script\">Identifying在bash shell脚本接收到的信号名称

当使用像陷阱func_trap INT TERM退出

func_trap () {
    ...some commands...
}

有没有在功能块的方式来检测陷阱叫的吗?

Is there a way in the function block to detect which trap has called it?

是这样的:

func_trap () {
    if signal = INT; then
        # do this
    else
        # do that
    fi
}

或者我需要写,做不同的东西每个陷阱类型的一个单独的功能?
是否有保存最新收到的信号进行bash的变量?

Or do I need to write a separate function for each trap type that does something different? Is there a bash variable that holds the latest received signal?

在此先感谢!

推荐答案

任何参数或变量没有文件提示持有该被困信号,所以你必须为你写希望每个陷阱函数/陷阱声明不同的表现。

No documentation hints of any argument or variable holding the signal that was trapped, so you'll have to write a function/trap statement for each trap you want to behave differently.

这篇关于是否有可能发现在bash * *哪些陷阱信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆