i need help with this linux shelll scritping Write the following script using yo
ID: 3679465 • Letter: I
Question
i need help with this linux shelll scritping
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.
In this assignment, you will create a script called mygrade that will calculate and then
display letter grade of CST8102. 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.
You are now ready to have your understanding checked and show the execution of your script to your professor by the professor.
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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.