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,我试图CTRL-C在它之前多次忽略或捕获(不是无限的)。
目前我知道如何忽略该命令一次。但我不知道如何增加或减少它被忽略的次数。
代码:
#! /bin/bash trap 'justonce' 2 justonce() { echo "you sure?" trap 2 } while true; do echo -n "." sleep 1 done
谢谢
使用循环和变量:
#! /bin/bash ignore=4 trap 'justonce' 2 justonce() { echo "you sure? $ignore left" if [ $((ignore)) -eq 0 ] then exit 1 fi ignore=$((ignore-1)) } while true; do echo -n "." sleep 1 done