Interrupt sleep in bash with a signal trap

后端 未结 3 1112
无人及你
无人及你 2020-12-04 18:23

I\'m trying to catch the SIGUSR1 signal in a bash script that is sleeping via the sleep command:

#!/bin/bash

trap \'echo \"Caught          


        
3条回答
  •  清歌不尽
    2020-12-04 18:42

    Remark that

    sleep infinity &
    wait
    

    puts the sleep in background, and stops the wait with the signal. This leaves an infinite sleep behind on every signal !

    Replace the sleep and wait with

    read
    

    and you will be fine.

提交回复
热议问题