Answered step by step
Verified Expert Solution
Link Copied!

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:

  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
    • Note: you have to escape * with a \, including on the command line
    • Use a default case (*) for an unknown operator
  3. 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
  4. 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
  5. Use echo to output the answer (or an error message if theres a problem)
  6. Be sure both the script you write and the script Im giving you have write permission (chmod u+x ... or chmod 744...)
  7. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions