如果你“source”另一个文件,之前定义的“trap INT”将不起作用?

发布于 2024-10-09 12:31:13 字数 353 浏览 0 评论 0原文

如果我将其放在 Bash 脚本的顶部,则 Control+C 不起作用。

exit-function() {
  echo "Hey hey!"
}    
trap exit-function INT

但如果我把它放在几行之后,那么 Control+C 就会被困住。

更新

如果将其放置在 source "$HOME/.rvm/scripts/rvm" 之后,那么它就可以工作。

因此,如果您获取另一个文件, 之前定义的trap INT 不起作用?

If I place this on the top the Bash script, Control+C doesn't work.

exit-function() {
  echo "Hey hey!"
}    
trap exit-function INT

But if I put it few lines after, then Control+C is trapped.

UPDATE:

If it's placed after source "$HOME/.rvm/scripts/rvm", then it works.

So if you source another file, trap INT defined before won't work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2024-10-16 12:31:13

rvm 脚本来源的脚本之一设置了一个 trap,它会替换您之前设置的陷阱。通过在 rvm 脚本之后设置一项,您将替换它设置的一项。

One of the scripts that's sourced by the rvm script sets a trap which replaces the trap you set earlier. By setting one after the rvm script you're replacing the one it sets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文