I have defined the following trap function.
gotill()
{
job=$(jobs)
bg=$(echo "$job" | grep "status &$"
if [ ! -z "$bg" ]; then
trap '' INT
else
echo "Warning, the next interrupt key (^C) will terminate the script!"
trap INT
fi
}
.
.
.
trap 'gotill' ILL
This function should trap the first ^C INT signal, after receiving the second one it should terminate the script with the warning message. However, if the program runs in the background all INT signals should be ignored.
When I try to interrupt the script with ^C it terminates immediately. Can anybody correct my code ?
Thanks!
gotill()
{
job=$(jobs)
bg=$(echo "$job" | grep "status &$"
if [ ! -z "$bg" ]; then
trap '' INT
else
echo "Warning, the next interrupt key (^C) will terminate the script!"
trap INT
fi
}
.
.
.
trap 'gotill' ILL
This function should trap the first ^C INT signal, after receiving the second one it should terminate the script with the warning message. However, if the program runs in the background all INT signals should be ignored.
When I try to interrupt the script with ^C it terminates immediately. Can anybody correct my code ?
Thanks!