如何读取shell脚本中的转义字符?
如何在shell脚本中读取control c、control z?
预先感谢
添加...
我的要求是,我删除脚本末尾的文件。如果脚本被停止(通过控制 c 或控制 z),我还需要删除该文件
How to read control c, control z in shell script?
Thanks in advance
added...
What is my requirement was, im deleting a file at the end of script. If the script was stopped (by control c or control z) also i need to delete that file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每次用户进行控制 c (或任何其他特殊组合)时,都会向您的脚本发送一个信号。
您需要使用 trap 命令在脚本中捕获此信号。
解释起来很长,但是这个网站包含了关于管理信号的很好的解释: http://linuxcommand.org/wss0160.php
Every time an user make control c (or any other special combination) a signal are send to your script.
You will need to capture this signal in your script using the trap command.
It's long to explain, but this web contain a good explanation about managing signals: http://linuxcommand.org/wss0160.php
阅读
man Kill
获取可以放在那里的允许信号列表,注意kill
手册页的SIGNALS
部分中的描述字段提到您的 shell 脚本可以阻止(捕获)哪些信号。注:Ctrl+c为INT(中断)信号
Read
man kill
for the list of allowed signals that you can put there, note the description field in theSIGNALS
section of thekill
man page that mentions which signal can be blocked (trapped) by your shell script.Note: Ctrl + c is the INT (interrupt) signal