Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Script You're going to create a basic shell script calculator that handles +, -, calculator.bash and/. Name it The input will look like this:
The Script You're going to create a basic shell script calculator that handles +, -, calculator.bash and/. Name it The input will look like this: /calculator.bash (This is called prefix notation, if you're curious) Ex: > ./calculator.bash - 15 7 8 Steps to take to create the script: 1. Check the number of arguments; it should be 3, no more, no less a. Use a "usage" function for this and other errors 2. Use case to determine the operator a. Note: you have to escape "*" with a \including on the command line b. Use a default case (*) for an unknown operator C. For some case examples see https://www.thegeekstuff.com/2010/07/bash-case- statement/ 3. Use functions for the four operators a. Implement them above where they are called (that is, the main functionality comes last) b. You'll 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 answers... to put the calculation into a variable; else it will be a string such as "5+6" 4. Use echo to output the answer (or an error message if there's a problem) 5. Be sure both the script you write and the script I'm giving you have write permission (chmod u+x ... or chmod 744...) 6. Test the script manually before using the script I'm giving you so it's 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. Notes For help doing arithmetic in a shell script, see https://ryanstutorials.net/bash-scripting- tutorial/bash-arithmetic.php. One key is that you can't use spaces inside the arithmetic (i.e. answer=$1+$2, not answer = $1 + $2
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