ksh 中的自定义陷阱信号
有没有办法让我在 ksh 中实现自定义假信号?目前正在捕获 ERR 信号并退出。但是,由于更改,有些调用可能不会返回成功,但这是一个有效的条件。在这种情况下,我想确保此调用生成不同的信号或以不同的方式处理 ERR。有办法做到这一点吗?
Is there a way for me to implement custom fake signals in ksh? Currently am capturing the ERR signal and exiting. However, due to a change, there are calls that may not return success, however that is a valid condition. In such case, I want to make sure that this call generates a different signal or handle the ERR differently. Is there a way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
kill
向当前 shell 发送任何您想要的信号。您可以在子 shell 中使用exit
或在函数中使用return
来设置所需的任何错误代码。试试这个脚本:
示例:
You can use
kill
to send any signal you want to the current shell. You can useexit
in a subshell orreturn
in a function to set any error code you want.Try this script:
Example:
也许您可以简单地将要特别处理其退出代码的语句包装在一个结构中,该结构将简单地执行您想要的操作(使用“或”或“如果不是”结构并分析退出代码)。
这似乎是一种更简洁的编程风格,不是吗?
Perhaps you could simply wrap the statements whose exit codes you want to treat specially in a construction that would simply do what you want (employing "or" or "if not" constructions and analyzing the exit codes).
That seems to be a much cleaner programming style, doesn't it?