Computing.Net > Forums > Linux > Bourne Shell Script Problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Bourne Shell Script Problem

Reply to Message Icon

Name: Mandy
Date: April 15, 2003 at 00:07:04 Pacific
OS: Mandrake Linux
CPU/Ram: 256
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: April 15, 2003 at 04:30:30 Pacific
Reply:

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.


0

Response Number 2
Name: dav
Date: April 15, 2003 at 20:04:47 Pacific
Reply:

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


0

Response Number 3
Name: David Perry
Date: April 16, 2003 at 05:52:58 Pacific
Reply:

#!/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 command

echo "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


0

Response Number 4
Name: Dlonra
Date: April 16, 2003 at 14:38:16 Pacific
Reply:

where did your "bourne" shell come from?
AFIK, mandy has bash.

try
man bash
or
man sh (if relly bourne)
search for "trap"


0

Response Number 5
Name: Mandy
Date: April 17, 2003 at 02:58:20 Pacific
Reply:

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.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Bourne Shell Script Problem

another bourne shell script prob www.computing.net/answers/linux/another-bourne-shell-script-prob/19772.html

Shell Script problem..need help! www.computing.net/answers/linux/shell-script-problemneed-help/22814.html

shell scripts www.computing.net/answers/linux/shell-scripts/19644.html