Possible Duplicate:
How to sort an array in BASH
I have numbers in the array 10 30 44 44 69 12 11...
. How to display the highest from array?
echo $NUM //result 69
To find the largest element from the array, a simple way is to arrange the elements in ascending order. After sorting, the first element will represent the smallest element, the next element will be the second smallest, and going on, the last element will be the largest element of the array.
Mode is the highest occurring figure in a series. It is the value in a series of observation that repeats maximum number of times and which represents the whole series as most of the values in the series revolves around this value. Therefore, mode is the value that occurs the most frequent times in a series.
You can use sort
to find out.
#! /bin/bash ar=(10 30 44 44 69 12 11) IFS=$'\n' echo "${ar[*]}" | sort -nr | head -n1
Alternatively, search for the maximum yourself:
max=${ar[0]} for n in "${ar[@]}" ; do ((n > max)) && max=$n done echo $max
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With