nickoli
December 3rd, 2007, 10:02 PM
I have a program that has a loop in it and also uses case. I want to somehow embed trap "" 2 so that I can hit control c while running the program without killing the program I've tried several approaches but no avail. Is there anyway to embed trap in my program so it will capture ctrl c. here is my last attemp at solving this problem.
bash-2.04$ more shorty
#### function
function nokill
{
trap "" 2
}
$(nokill)
echo Choice\?
read input
while [ "$input" != "stop" ]
do
$(nokill)
case $input
in
[0-9]* ) echo Positive Integer
echo input
read input ;;
-[0-9]* ) echo Negative Number
echo input
read input ;;
date ) date
echo input
read input ;;
[Ss][Tt][Oo][Pp]) exit 0 ;;
* ) echo "Boldly goes where no man has gone before!"
echo input
read input ;;
esac
done
bash-2.04$ more shorty
#### function
function nokill
{
trap "" 2
}
$(nokill)
echo Choice\?
read input
while [ "$input" != "stop" ]
do
$(nokill)
case $input
in
[0-9]* ) echo Positive Integer
echo input
read input ;;
-[0-9]* ) echo Negative Number
echo input
read input ;;
date ) date
echo input
read input ;;
[Ss][Tt][Oo][Pp]) exit 0 ;;
* ) echo "Boldly goes where no man has gone before!"
echo input
read input ;;
esac
done