Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I help with with this linux please! You will create a script file to perform bas

ID: 3688145 • Letter: I

Question

I help with with this linux please! You will create a script file to perform basic calculations. Create a script file called mycalc using vim. The first line of your script file should force the use of the bash shell. Your script file should be properly commented The script file should perform the following operations: + and - The script should have two functions: add and subtract Each of the functions should accept two integer numbers as parameters The functions should perform the desired calculation. The script file should support two ways of functioning, no parameters or three parameters. If three parameters are provided, the second parameter must be + or -: The First and Third parameters must be numbers. The user can enter integer numbers only. The result should be displayed on the screen and the program exit. The example below shows how plus would work. Do similar for - Example: mycalc 12 + 3 The sum of 12 plus 3 equals 15 If no parameters are provided the script should do the following: A menu should be provided allowing the user to exit or Do a calculation. Allow upper or lower case. See Menu 1 below. If C is selected the screen should clear and the user should be prompted to enter a number. See Menu 2 below. If a number is entered the screen should clear and a new menu should be displayed. See Menu 3 below. If + or - is entered the screen should clear and the user should be prompted to enter a number. See Menu 2 below. If a number was entered the result should be shown on the screen After three seconds the screen should clear and Menu I should be displayed again. Error checking should be done to make sure of the following: Either no parameters or three parameters are entered. If three parameters arc entered then the second parameter must be one of the following + - Any invalid choices should be flagged in the menu system You don't need to check if the input numbers are integer

Explanation / Answer

#! /bin/bash
# The rest of your script.

echo -e "$Bold MYCALC $Normal "

items="1. ADDITTION
2. SUBTRACTIOn
X. EXIT"

choice=
#####################################################################
# Define Functions Here #
####################################################################

exit_function()
{
clear
exit
}

#Function enter is used to go back to menu and clears screen

enter()
{
unset num1 num2
ans=
echo ""
echo -e "Do you want to continue(y/n):c"
stty -icanon min 0 time 0

# When -icanon is set then one character has been received.
# min 0 means that read should read 0 characters.
# time 0 ensures that read is terminated the moment one character
# is hit.

while [ -z "$ans" ]
do
read ans
done

#The while loop ensures that so long as at least one character is
# not received read continue to get executed

if [ "$ans" = "y" -o "$ans" = "Y" ]
then
stty sane # Restoring terminal settings
clear
else
stty sane
exit_function
fi
}

#####################################################################
# Main Starts #
#####################################################################

while true
do
echo -e "$Bold PROGRAM MENU $Normal "
echo -e " $items "
echo -n "Enter your choice : "
read choice

case $choice in
1) clear
echo "Enter two numbers for Addition : "
echo -n "Number1: "
read num1
echo -n "Number2: "
read num2
echo "the sum of a and b = `expr a + b`"
enter ;;
2) clear
echo "Enter two numbers for Subtraction : "
echo -n "Number1: "
read num1
echo -n "Number2: "
read num2
echo "the subtract of a and b = $((num1-num2))"
enter ;;
X) exit_function ;;
*) echo "You entered wrong option, Please enter 1,2,X"
echo "Press enter to continue"
read
clear
esac