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.
我想在 bash 中这样做:
trap "echo Don\'t do that!" 2 3
这工作得很好,除了我希望脚本继续。我怎样才能做到这一点?如果我将命令保留为空白字符串,脚本将继续,但不打印任何内容。我可以同时打印消息并继续吗?
使用此脚本:
#!/bin/bash trap 'echo "Whee!"' 3 2 echo "Setting up.." sleep 5 echo "Done."
我得到这个输出:
Setting up.. ^CWhee! Done.
^C..当我在sleep命令期间发送一个。发送中断;bash捕获它并继续,但中断由sleep. 这不是你想要的吗?
^C
sleep
bash