Program to compute average in bash.
Input : 1 2 3 4 5 Output : average : 3.0 Input : 1 2 3 4 10 Output : average : 5.0
Program to compute average is simple. It is also called as Mean.
(sum of all elements) / (total no. of elements)
The extension for bash programs end with .sh. Elements are stored in array which are traversed in while loop to calculate the sum. It is recommended to understand Arrays in Shell.
The avg is caculated using bc command. bc command is used for command line calculator.
Programs in bash is executed as follows :
sh program_name.sh OR ./program_name.sh