Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trap function

Status
Not open for further replies.

sfu

Programmer
Oct 13, 2003
10
US
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!
 
After posting my code, I saw what was wrong... I messed up with the trap call, I should have instead called the trap 'gotill' with the "INT" signal.

Problem solved...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top