473,624 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bash script of a simple calculator

lifeisgreat20009
70 New Member
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 17751
Banfa
9,065 Recognized Expert Moderator Expert
You're entering n1 and n2 and then operating on a and b
Jan 4 '09 #2
lifeisgreat20009
70 New Member
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 Recognized Expert Moderator Expert
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 Recognized Expert Top Contributor
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
lifeisgreat20009
70 New Member
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
2985
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 out how to do this in bash script as the requirement is necessary for a migration script to obtain the code from a .cfg file and then be able for the "parent" script to run the code it "imported" from the .cfg file, much like PHP's require() or...
3
5207
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
2933
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 anyone help me on this please. and also during the operation selection, if ill enter a character it wont go back to the main program. by the way, my compiler is Dev-C++. I need help badly..here's my code below... #include <iostream.h> #include...
1
1498
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, comprised between 300 and 600, of binary files of dimension comprised between 10 Kbytes and 30 kbytes. Also the names of the files are random and are composed from 20 chars plus the jpg extension." Working sample: createdata /data 20
1
1817
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 executed otherwise it skips the commands. However, since this script is executed every 5 minutes the trigger variable is reset upon each time the script is executed. Can anyone recommend a method which I can use to keep the value of the trigger variable...
6
3480
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 positive input -assumes all real #'s -assumes operands and operators in expression are separated with spaces here is what I have so far:
3
3856
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. The problem is that when I uninstall it, my program keeps running in the background, even if the files are deleted. I know I can terminate python shell directly, but this is not a good ideabecause the end-user may be working with another important...
1
2981
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 select the one containing the name of my script ? _________________________________________________________________ Votre contact a choisi Hotmail, l'e-mail nouvelle génération. Créezun compte. http://www.windowslive.fr/hotmail/default.asp
0
2008
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 another wrote: py s.py tokens & capture=$! (get the PID ready)
0
3704
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, ffmpeg keeps running. How would one kill ffmpeg from within the script? In case it's needed, here is the line that calls both ffmpeg and Zenity: ffmpeg -i "${vid}" -f mp4 -vcodec mpeg4 -qmax 7 -acodec aac -s 320x240 -aspect $aspect "${vid}.mp4" |...
0
8234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8677
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.