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
- Bash shell script to swap two numbers
- Bash shell script to find out the largest value from given command line arguments
- Write a bash script to print a particular line from a file
- Bash program to check if the Number is a Prime or not
- Fibonacci Series in Bash
- Useful and time saving bash commands in Linux
- Bash program to find A to the power B
- Bash program to check if the Number is a Palindrome
- Sorting an array in Bash using Bubble sort
- Simple Calculator in Bash
- Bash shell script to find sum of digits
- Programs for printing different patterns in Bash
- Bash Script to get Low Battery Alert in Linux
- How to Fix Minimal BASH Like Line Editing is Supported GRUB Error In Linux?
- Leap Year Program with Bash Shell Scripting in Windows
- Working with Magic numbers in Linux
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.