The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-24-2008
Ernst Ernst is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 37
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!
  #2 (permalink)  
Old 09-24-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,777
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
This is a start
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0