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!

Menu Considerations 3

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

I have a few questions in trying to enhance a menu using a Bourne shell script on Solaris 8.

1. In the past I have used read OPTION to grab user input but this requires a user to press "Enter". Is there a way to grab a single key input and execute it immediately without requiring an "Enter" key being pressed?

2a. How can I use extended ASCII line characters?
Can you give an example please.
2b. Where can I find a list of the characters that can be used?

Thanks,

Michael42
 
I'd write a C prog with the curses library ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
One way to do that (idea from SamBones) is to set an extremely low timeout for canonical reads: (But it is then impossible to differentiate between a timeout and the user just hitting enter...)

Code:
#!/bin/ksh

OLDSTTY=`stty -g`

echo "
1. Steak
2. Lasagna
3. SpareRibs
4. Quit"

stty -icanon min 0 time 1 # read timeout 0.1 seconds
echo "Enter choice: \c"
while :
do
 line | read choice junk
 if [ "${choice}" != "" ]
 then
  echo
  break
 fi
done
stty "${OLDSTTY}"

case "${choice}" in
 1) echo "Steak coming up, you want fries with that?";;
 2) echo "Lasagna coming up, you want one or two rolls with that?";;
 3) echo "SpareRibs coming up, you want fries with that?";;
 4|q|Q) echo "Not hungry then?"; exit;;
 *) echo "Sorry, ${choice} is not on the menu";;
esac
echo



HTH,

p5wizard
 
Hi,

Try this part of code ( extract from sysadmin magazine if my remembers is good )
Code:
#----------------------------------
# subroutine to read one char
#----------------------------------
function getchar {
        typeset OLDSTTY=$(stty -g 2>/dev/null)
        stty -icanon -echo min 1 time 0 2>/dev/null
        typeset CAR=$(dd bs=1 count=1 <&0 2>/dev/null)
        stty $OLDSTTY 2>/dev/null
        print $CAR
}

print "Answer Y N or Q to quit : \c"
C1=$(getchar)
print "You typed : $C1"
# treat the answer given
....
 
aau,

Thanks very much the the very detailed response.

-Michael42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top