1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages.zh/common/trap.md

18 lines
343 B
Markdown
Raw Permalink Normal View History

2019-03-18 12:17:28 +08:00
# trap
> 在接收到事件时执行命令。
> 可用于对用户中断或其他操作执行清理。
> 更多信息:<https://manned.org/trap.1posix>.
2019-03-18 12:17:28 +08:00
- 列出命令和预期事件的名称:
2019-03-18 12:17:28 +08:00
`trap`
2019-03-18 12:17:28 +08:00
- 在接收到信号时执行命令:
2019-03-18 12:17:28 +08:00
`trap 'echo "捕获到信号 {{SIGHUP}}"' {{HUP}}`
2019-03-18 12:17:28 +08:00
- 移除命令:
2019-03-18 12:17:28 +08:00
`trap - {{HUP}} {{INT}}`