I need with this linux shell program please the last person got it wrong, thanks
ID: 3680075 • Letter: I
Question
I need with this linux shell program please the last person got it wrong, thanks!
Procedure
Write the following script using your Linux virtual machine. You must use vim as the editor.
The first line of your script file should force the use of the bash shell as the command interpreter. Your script file should be properly commented, including your lab section number, your name, and your student ID etc. Note that marks will be deducted for scripts without proper comments.
In this lab, you will create a script called Grades that will calculate and then display letter grade of LinuxTest. Use only integers for grade calculations.
1. Get user inputs of the following grades:
Assignments 40%
Test1 15%
Test2 15%
Final exam 30%
Note: To avoid decimal places in calculations, you may prompt the user to input an integer percentage number for each of the items listed above. You don't have to handle invalid input.
2. Calculate the number grade by adding up the four grades input by user
3. Convert the number grade to letter grade using the table below:
(Hint: use “Multilevel if-then-else” or case statement)
Number Grade Letter Grade
90 - 100 A+
85 - 89 A
80 - 84 A-
77 - 79 B+
73 - 76 B
70 - 72 B-
67 - 69 C+
63 - 66 C
60 - 62 C-
57 - 59 D+
53 - 56 D
50 - 52 D-
0 - 49 F
The screenshot below demonstrates the execution of this script file.
user1@localhost:~$./grades
Enter assignment mark (0 to 40): 25
Enter Test1 mark (0 to 15): 8
Enter Test2 mark (1 to 15): 10
Enter Final Exam mark (1 to 30): 24
Your final grade is C+
user1@localhost:~$
Explanation / Answer
#!/usr/bin/env bash
read -p "Please enter your choice: " response
## If the response given did not consist entirely of digits
if [[ ! $response =~ ^[0-9]*$ ]]
then
## If it was Quit or quit, exit
[[ $response =~ [Qq]uit ]] && exit
## If it wasn't quit or Quit but wasn't a number either,
## print an error message and quit.
echo "Please enter a number between 0 and 100 or "quit" to exit" && exit
fi
## Process the other choices
if [ $response -le 49 ]
then
echo "F"
if [ $response -gt 50 -le 52 ]
then
echo "D-"
elif [ $response -gt 53 -le 56 ]
then
echo "D"
elif [ $response -gt 57 -le 59 ]
then
echo "D+"
elif [ $response -gt 60 -le 62 ]
then
echo "C-"
elif [ $response -gt 63 -le 66 ]
then
echo "C"
elif [ $response -gt 67 -le 69 ]
then
echo "C+"
elif [ $response -gt 70 -le 72 ]
then
echo "B-"
elif [ $response -gt 73 -le 76 ]
then
echo "B"
elif [ $response -gt 77 -le 79]
then
echo "B+"
elif [ $response -gt 80 -le 84 ]
then
echo "A-"
elif [ $response -gt 85 -le 89 ]
then
echo "A"
elif [ $response -gt 90 -le 100]
then
echo "A+"
elif [ $response -gt 100 ]
then
echo "Please enter a number between 0 and 100"
exit
fi