Question
Example 2: Simple calculator and user interaction #!/bin/bash while [ -z $arg1 ] #will be repeated until a data will be entered do read p
Example 2: Simple calculator and user interaction
#!/bin/bash
while [ -z $arg1 ] #will be repeated until a data will be entered
do
read p Enter argument1: arg1
done
while [ -z $arg2 ] #will be repeated until a data will be entered
do
read p Enter argument2: arg2
done
echo Youve entered: arg1=$arg1 and arg2=$arg2
let addition=arg1+arg2
let subtraction=arg1-arg2
let multiplication=arg1*arg2
let division=arg1 / arg2
let reminder=arg1 % arg2
echo e results:
echo $arg1+$arg2=$addition
echo $arg1-$arg2=$subtraction
echo $arg1*$arg2=$multiplication
echo $arg1/$arg2=($division+$reminder/$arg2)
3.1. (Script 1) You are supposed to MODIFY example script provided in the Example 2 so that it would perform operations +, -, *, / (only the whole part of the division operation, ignore the reminder part) and ^ (power). When it comes to the first four operations, they are normally supported by let command or the other alternative ways of calculating numerical expressions mentioned in the lecture slides (and these are actually already programmed in the Example 2). However, the power operation will need to be implemented by you, probably in the form of some sort of loop operations (I am leaving this to you to decide). Once you write the script, you will be required to upload it to the scriptcheck.cms.gre.ac.uk system for test purposes. The marking system will assume that the script will be processing three command line parameters, one for the first argument of arithmetic operation, the second command line parameter for the second argument of the arithmetic operations and third parameter expressing the arithmetic operation to be processed. Your script will be executed from the command line, for example, in order to check if your solution is correct it might be executed as: scriptname 4 2 operation The scriptcheck system will check if you script returns appropriate results for each operation; for the example execution parameters (4 and 2) it should return:
4 2 + -> 6
4 2 - -> 2
4 2 * -> 8
4 2 / -> 2
4 2 ^ -> 16
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