Hi Team ,
I wrote a shell script for adding and subtracting two numbers am getting error could some one please help to fix it
script:
error am getting is:
Last edited by Don Cragun; 02-01-2018 at 01:16 AM..
Reason: Add CODE tags.
If this is not a homework question, please explain what you are working on, how this script will be used, what operating system you're using, and what shell you're using. Without this basic information, we can waste a lot of time making assumptions about what might or might not work in your environment.
If you are really, truly needing to provide some way for your end users in a production environment to add or subtract numbers at the command line, there's no sense in re-inventing the wheel here. UNIX already provides a fair number of ways to do this, the easiest of which is the bc utility.
It can be run interactively, like so:
Or you can pipe things into it:
Or it can read its input from a file:
and so on and so forth. It really would be a complete waste of your own time to write a shell script specifically to do calculation, when UNIX provides a built-in utility for doing precisely this.
Now, if this is a homework assignment (and personally, I really can't see any reason why you'd need to write a script like this outside of academia) that's absolutely fine - honestly, we really don't mind, and are always happy to help. But you would need to follow the homework rules as mentioned by Don Cragun, and as outlined here.
Alternatively, if there's some truly bizarre and currently-unimaginable reason why you absolutely MUST write such a script in a production environment, please let us know exactly what that is and I'm sure we can help. But honestly, bc is such a better answer than anything any one person could ever write a shell script to replace. Your users' own desktop OS calculator applet would be a better answer, to be frank.
Since you refuse to tell us for whom you work, what shell you're using, and what operating system you're using; I have to say that this looks like homework and not like a serious piece of code that any IT professional would release to a normal user.
Therefore, I can only say that my guess at your problem is that your code does not follow the syntax used by a shell that accepts Bourne shell syntax for a case statement. Bourne shell case statement syntax does not allow any code like read statements between the ;; ending the code to be executed for a given pattern and the start of the next pattern matching expression. Your code is also missing the line of code that terminates every case statement. And, of course, your code is using two functions but never defines those functions. It is also unclear to me why you would want to run those two functions concurrently instead of running them sequentially in the code that both adds and subtracts numbers.
You say that your code is supposed to add and subtract numbers, but you haven't said what is supposed to be done with the calculated sum and difference. You haven't specified the format of the numbers to be processed (unsigned or signed numbers; integer, floating point, or complex numbers; decimal only or decimal, octal, hexadecimal, and/or other bases; etc.).
Therefore, there is no way for us to guess at what code you need to reach your goal. And, until you give us some reason to believe that this is not homework (like several other requests we have seen in the past asking for help with VERY similar tasks that were homework assignments) we can't take the chance of doing your homework for you in violation of several educational institutions' guidelines of institutions that support the work we do at The UNIX & Linux Forum.
This User Gave Thanks to Don Cragun For This Post:
Hi All,
I have written a menu driven bash shell script.
Current Output is as below:
-------------------------------------
Main Menu
-------------------------------------
Option 1
Option 2
Option 3
Option 4
Exit
=====================================
Enter your... (3 Replies)
HI All..
below is my menu options script. in option 2,3 and 4 im giving input and they are saving into their respective text file.
problem is when im trying to "cat" those files in options 7,8 and 9 im not getting the output. no respective file contents are displaying on screen. but if i... (1 Reply)
My employers would like me to selectively run one of several different (already-existing) Korn Shell menu-driven scripts out of the user's .profile file, depending on some yet-to-be-specified user critieria.
I've never done this kind of thing, but I have the existing scripts (among other... (5 Replies)
I'm a beginner at scripting and have been putting this script together over the past week. It's no where as polish as it could be. Any tips/suggestions on improving this script would be appreciate it. Every week, my team develops WAR files in tomcat on our test environment and moves them to our... (4 Replies)
Hi, I was wondering if someone could help me write a shell script in Linux that backsup/restores data to anywhere I choose but it needs to be menu driven?
Thanks, I'm new to Linux/Unix but liking it so far...just hoping to get to grips with the scripts! :) (7 Replies)
i'm confused what this means.
i was asked to design a menu or command line option driven script that reads out of a DB and displays info such as
read_data.pl -u <user> -e <event>
which would print commands run by <user>with the <event> in the db.
any suggestions? i've been using... (2 Replies)
QUESTION:
Write shell script using menu-driven approach to show various system configuration like
1) Currently logged user and his logname
2) Your current shell
3) Your home directory
4) Your current path setting
5) Your current working directory
6) Show Currently logged number of... (1 Reply)
Hi Guys..
am new to unix scrpiting..I need a Menu need to create using shell scrpting
eg:
Food items
ready
paid
if i press "f" need to add items for a file food items..
if i press "r" it need to move into ready and remove from food items
if i press "p" need to update a filed in... (1 Reply)
How do I assign values to reference variables?
I am assigning a variable name to --> $user_var
Then I am trying to change its underlying variable value by
$((user_var))=$user_value .. its failing,,
Please let me know if there is a way to do this dynamically..
FileA.props... (5 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
1) Write a Menu Driven Shell Script which accepts1 to 5 options and performs the following actions for... (1 Reply)