Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有以下功能:
#!/usr/bin/env bash f(){ trap 'printf "\nAborting\n"; return 1' SIGINT sleep 10 return 0 }
如果我运行f并等待那 10 秒然后执行
f
$ echo $? > 0
这是预期的。但是,如果我运行f并点击Ctrl+c,该功能f将被中止,但是
Ctrl+c
而不是1. 我认为我没有正确地陷印,但不知道如何解决它。
1
您必须使用exit而不是return. 所以这将是
exit
return
trap 'printf "\nAborting\n"; exit 1' SIGINT