473,326 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

bash script of a simple calculator

lifeisgreat20009
Expand|Select|Wrap|Line Numbers
  1. Echo “Enter first number:”
  2. Read n1
  3. Echo “Enter Second number:”
  4. Read n2
  5. Echo “Enter operation to be carried out that is +, - , / or X”
  6. Read opr
  7. If [ opr==”+” ]
  8. Then
  9. echo $(( $a + $b ))
  10. elif [ opr==”-“]
  11. then
  12. echo $(( $a - $b ))
  13. elif [ opr==”/” ]
  14. then
  15. echo $(( $a / $b )) 
  16. elif [ opr==”X” ]
  17. then
  18. echo $(( $a * $b ))
  19. fi
  20.  
Is the script above correct syntactically ?? its not working fine. I searched net for syntax errors but all seems to be correct. Plz tell me where modifications are needed in the code ?
thnx and regards
Jan 4 '09 #1
5 17720
Banfa
9,065 Expert Mod 8TB
You're entering n1 and n2 and then operating on a and b
Jan 4 '09 #2
otherwise is it ok ??
I made changes here only by mistake..
Its a and b only in the original script
Jan 4 '09 #3
Banfa
9,065 Expert Mod 8TB
Sorry I'm not a bash expert it is just appeared to be an obvious mistake in any programming language.
Jan 4 '09 #4
gpraghuram
1,275 Expert 1GB
Hi,
There are some couple of errors in the code .
check this
Expand|Select|Wrap|Line Numbers
  1. echo "Enter first number:" 
  2. read a 
  3. echo "Enter Second number:" 
  4. read b 
  5. echo "Enter operation to be carried out that is +, - , / or X" 
  6. read opr 
  7. #echo "opr =$opr"
  8. if [ $opr = "+" ] 
  9. then 
  10.     op=`expr $a + $b`
  11.     echo "$op"
  12. elif [ $opr = "-" ] 
  13. then 
  14.     op=`expr $a - $b`
  15.     echo "$op"
  16. elif [ $opr = "/" ] 
  17. then 
  18.     op=`expr $a / $b`
  19.     echo "$op"
  20. elif [ $opr = "X" ] 
  21. then 
  22.     op=`expr $a \* $b`
  23.     echo "$op"
  24. fi 
Raghu
Jan 5 '09 #5
thank you very much..its working now
Jan 5 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Phil Powell | last post by:
I'm sorry but I can't figure out how to explain this any better than this. In PHP we have a command "require()" that obtains a file and logically places it into another file. I cannot figure...
3
by: Paul | last post by:
I want to make a simple calculator program but dont know where to get started. This is not GUI but a simple terminal program. It would get input like this Enter number: 5 + 10
1
by: Synapse | last post by:
Hello... We were asked to create a simple calculator program in our C++ subject by using loops only. i have a problem in creating a loop in the multiplication and division operation so please can...
1
by: alexxxprog | last post by:
Thank you very much for who can solve this bash script: "Create on the filesystem a bash proceedure createdata that creates collections that that will have to contain a variable, a random number,...
1
by: pnjbi | last post by:
Hi, I've created a bash script which is executed every 5 minutes through a cron. The script checks if a trigger variable has been set to execute certain commands. If it is the commands are...
6
by: NoviceJava | last post by:
I'm new to JAVA and need some help writing a simple calculator program. Here are the instructions: -expects espression with 2 operands together with either +, -, *, or / operator -espects only...
3
by: Gros Bedo | last post by:
Hello :-) I have a question about Python and Linux shell. I have a python program which is permanently resident in the end-user system. I'm currently producing a RPM package, and it works nicely....
1
by: Gros Bedo | last post by:
Yes I've seen that each python script calls its own instance of Python. Buthow to know which is the good one in bash ? Is there a command that gets the parameters of process, so I could use grep to...
0
by: norseman | last post by:
Gros Bedo wrote: ============================== Yes. man ps explains try ps -AFL | grep then kill -9 found (check it more than twice) 1) If your script is known to hang use what...
0
by: kidko | last post by:
I've written a Zenity frontend for ffmpeg using a Bash script. However, if the user hits "cancel" in the progress dialog (incurring the --auto-kill option), the bash script is killed. Unfortunately,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.