Question: 4.5) Please use the solution to HW 7, problem 2, as a template to write a shell/awk script, myaverage4 , that reads in 4 numbers

4.5) Please use the solution to HW 7, problem 2, as a template to write a shell/awk script, myaverage4, that reads in 4 numbers and then uses a self-defined function to compute the average. The average should be displayed in the main program, not inside the function. Please use the following testing cases to test your script:

$ ./myaverage4 2 7 4 3

The average is 4

$./myaverage4 -2 -1 -4 -5

The average is -3

This is what i have:

#!/usr/bin/

echo $1 $2 $3 $4| awk '

{

print avg($1 $2 $3 $4)

}

function avg (a,b,c,d){

x=0

y=0

x = a + b + c + d

y = x / 4

return y

}'

it doesnt seem to be working.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!