Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please don't copy from other chegg or google answers thank you. The Script Youre going to create a basic shell script calculator that handles +,
Please don't copy from other chegg or google answers thank you.
The Script
Youre going to create a basic shell script calculator that handles +, -, *, and /. Name it
calculator.bash
The input will look like this: ./calculator.bash
(This is called prefix notation, if youre curious) Ex:
> ./calculator.bash 15 7
8
Steps to take to create the script:
- Check the number of arguments; it should be 3, no more, no less a. Use a usage function for this and other errors
- Use case to determine the operator
- Note: you have to escape * with a \, including on the command line
- Use a default case (*) for an unknown operator
- Use functions for the four operators a. Implement them above where they are called (that is, the main functionality comes last) b. Youll have to pass in the arguments for the function. For both the script itself and
- functions, the arguments are numbered ($1, $2, etc.) c. Say let answer=... to put the calculation into a variable; else it will be a string such as 5+6
- Use echo to output the answer (or an error message if theres a problem)
- Be sure both the script you write and the script Im giving you have write permission (chmod u+x ... or chmod 744...)
- Test the script manually before using the script Im giving you so its easier to check things
a. For debugging help run the script with bash -eux calculator.bash. This will print out each line that gets executed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started