GIDForums  

Go Back   GIDForums > Computer Forums > Computer Software Forum - Linux
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-May-2008, 21:42
lilballeer lilballeer is offline
New Member
 
Join Date: May 2008
Posts: 16
lilballeer is on a distinguished road

Writing simple script in Linux


Hello,
I am trying to write a simple script in Linux that will choose one of the options from the menu(add, subtract, mulitply, divide), and do one of the operations...
I do not know exactly where to put the options for the input of the numbers...i think that is the part that is messing up the script...

here is what i have:

#!/bin/sh
clear
echo "M To do Multiplication"
echo "D To do Division"
echo "Q To quit"
read option
while [ $option != Q]

echo "Please enter a number"
read num1
echo "Please enter another number"
read num2
do
case $option in
A) echo "THe sum of $num1 and $num2 is: `expr $num1 + $num2`";;
S) echo "The difference of $num1 and $num2 is: `expr $num1 - $num2`";;
M) echo "$num1 multiplied by $num2 is: `expr $num1 * $num2`";;
D) echo "$num1 divded by $num2 is: `expr $num1 / $num2`";;
*) echo "That was an invalid selection";;
esac
while [option = Q]
do
exit
echo "Good Bye"


__________________________________________________ ____________
  #2  
Old 12-May-2008, 08:01
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,623
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Writing simple script in Linux


Quote:
Originally Posted by lilballeer
I am trying...

The while construct is

Code:
while [ condition ] do statements done

So your bash script could look something like

Code:
# show menu # prompt for option read option while [ $option != Q ] do #prompt for num1 read num1 #prompt for num2 read num2 case $option in # #case stuff for the operations # esac # show menu # prompt for option read option done echo "Goodbye"

Regards,

Dave
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Remove Linux And Install Windows? rockaway Computer Software Forum - Windows 3 06-Mar-2008 21:00
Need Free Website Templates sam_dezine Web Design Forum 8 06-Sep-2006 03:25
Pixel script Template customization gatufats Web Design Forum 2 29-Jun-2006 04:05
Who Is A Web Designer ? alicehopkins Web Design Forum 1 13-Jun-2006 02:56
HTML Code amgujral Web Design Forum 0 07-Apr-2006 09:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:34.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.