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

Write a shell script that performs the following steps: Input 7 numbers in a loo

ID: 664364 • Letter: W

Question

Write a shell script that performs the following steps:

Input 7 numbers in a loop (one at a time for each loop iteration). Validate the input that it is an integer number greater than or equal to 0 using regular expression handling – and prompt the user to re-enter the number if it is not valid.

Make a sum of these numbers that are valid inputs. Count how many of the input numbers that are greater than 250 (i.e., 1-7).

Then output the total sum of these numbers, as well as how many numbers were input that were greater than 250.

In addition to the above steps, make sure you include the following elements:

Use of grep/egrep or other Linux command for input integer validation

Use of conditional logic (e.g., use of do loop).

Use of functions where appropriate

Explanation / Answer


#!/bin/bash

total=0

c=0

//using for loop user declaring number
for a in {1..3};

do
// input statement
        echo -n "Write a number : "

        read i

// checking the condition whether number is greater than 250
        if [ $i -ge 250 ] ; then let "c=c+1"

        fi
// calculating sum of total
        let "total = i + total"

done
// displaying total value
echo "total = $total"


echo " > 250 = $c "

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote