Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
How to write bourne shell script that will
prompt the user for a number and which can
be ended only by the user typing STOP. The
script should ignore the interrupts from
Control +C and Control +\ and should
display a message specifying the interrupt.

Your homework assignment should contain a while loop and "trap". Please post specific questions regarding the portions of this task you are having trouble with.

i have the same problem too ...below is the
one that i have wrote..however, i dont know
how to use the trap and dont have any idea
how to ignore the interupts
#!/bin/sh
#PAGE 40
number=1
#set IGNOREEOF=10
while [ $number!="STOP" ]||[ $number!=NULL
] #||[ IGNOREEOF=9 ]
do
#set IGNOREEOF:ctrl+c:ctrl+
echo "Enter a number:"
read number
echo "The number you have entered
is $number"
done
....please help..by the way,....what is
IGNOREEOF ....i found it in the book but i
dont know how to use

#!/usr/bin/ksh
# http://linux.oreillynet.com/lpt/a/66# Signal Number Signal Name Explanation
# 0 EXIT exit command
# 1 HUP When session disconnected
# 2 INT Interrupt -- often CTRL-c
# 3 QUIT Quit -- often CTRL-\
# 15 TERM From kill commandecho "Please type STOP to exit"
# typeset -i answer=0
while [ "$answer" != "STOP" ] ; do
trap 'echo "`basename $0`: Interrupt attempted." 1>&2' 2 3
echo "Please input a number: " ; read answer
echo $answer
done

where did your "bourne" shell come from?
AFIK, mandy has bash.try
man bash
or
man sh (if relly bourne)
search for "trap"

Thank you very much for the help.
However I discovered there is sligthly difference in using "trap" between bourne shell and korn shell.
I didn't used 1>&2 but I added an echo statement instead. It works the same way as the what is written in the Korn shell otherwise it is not really the same.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |