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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case statement in Korn Shell 2

Status
Not open for further replies.

idiotboy

Programmer
Joined
Apr 20, 2001
Messages
21
Location
GB
Hi,

I've got the syntax for the case statement in korn shell (running on Solaris) but I can't figure out how to pose a question and read the answer as the input to the case statement. Do I just

print "Quesion:y/n"
read ans

ans="y"
case $ans in
y) print "blah blah";;
n) print "blah blah blah";;
esac

help

idiotboy
 
You've pretty much got it. Don't think you should be setting ans="y" after you've read it though ...

echo "Question:y/n"
read ans

case $ans in
y) print "you entered y";;
n) print "you entered n";;
*) print "enter y or n";;
esac

Greg.
 
It looks like you have it correct:

#!/bin/ksh
echo "Question:y/n"
read ans
case $ans in
"y[Y]")
echo "You've entered Yes."
;;
"n[N]")
echo "You've entered No."
;;
*)
echo "please enter a Y or N"
;;
esac


-Jared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top