Files
tldr/pages.zh/linux/trap.md

20 lines
392 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# trap
> 在事件发生时执行命令。
> 更多信息:<https://www.gnu.org/software/bash/manual/bash.html#index-trap>。
- 列出可用的事件名称(例如 `SIGWINCH`
`trap -l`
- 列出命令和预期事件的名称:
`trap -p`
- 在接收到信号时执行命令:
`trap 'echo "捕获信号 {{SIGHUP}}"' {{SIGHUP}}`
- 移除命令:
`trap - {{SIGHUP}} {{SIGINT}}`