Catch SIGINT in bash, handle AND ignore

后端 未结 1 1286
挽巷
挽巷 2020-12-15 03:33

Is it possible in bash to intercept a SIGINT, do something, and then ignore it (keep bash running).

I know that I can ignore the SIGINT with

trap \'\         


        
相关标签:
1条回答
  • 2020-12-15 03:52

    trap will return from the handler, but after the command called when the handler was invoked.

    So the solution is a little clumsy but I think it does what is required. trap handler INT also will work.

    trap 'echo "Be patient"' INT
    
    for ((n=20; n; n--))
    do
        sleep 1
    done
    
    0 讨论(0)
提交回复
热议问题