I created a script that adds four numbers that you enter: Example:
./myawkaverage 8 7 9 4
28
I need my script to add those four number and display the average so the results look like this:
Example:
./myawkaverage 8 7 9 4
The average is 7
I also need the script to accept negative numbers.
My script so far looks like this:
#!/bin/bash
echo $1 $2 $3 $4 | awk '
{
print sum3($1, $2, $3, $4)
}
function sum3(a, b, c, d) {
return (a + b + c + d)
}'