![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| case statement | bkan77 | Shell Programming and Scripting | 5 | 09-11-2007 06:54 PM |
| with Regard to Case Statement | cosec | Shell Programming and Scripting | 4 | 09-04-2007 03:15 AM |
| turning case into a if statement | brentdeback | Shell Programming and Scripting | 2 | 12-03-2005 12:12 AM |
| Case Statement | Zeta_Acosta | Shell Programming and Scripting | 19 | 04-06-2004 05:16 PM |
| case statement | Bab00shka | Shell Programming and Scripting | 1 | 07-15-2002 06:31 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
If or Case Statement
I want to write a program with the following variables:
a=7000 b=24000 c=613.8 The user can enter two words: Vivid or Blue for example. The challenge is that the user might not want to write the words the way they appear. The user can write V or v or vivid or Vivid or write Blue or blue, or B, or b What I want to do is to ask the user which word he/she wants to write. If the user enters any of the four choices for vivid, I want the program to do a / c. If the user decides to write any of the four choices for Blue, the program should do b / c. Who can help with that? Thanks! |
|
||||
|
Code:
#!/bin/ksh
a=7000
b=24000
c=613.8
echo "Please enter vivid or blue \c"
read ans
echo "$ans" | tr -s '[:upper:]' [:lower:]' | read answer
case $answer in
b*) printf "%f\n", $( echo " $b / $c " | bc -l) ;;
v*) printf "%f\n", $( echo " $a / $c " | bc -l) ;;
*) echo "invalid response" ;;
esac
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|