473,396 Members | 1,784 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,396 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 17738
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.