How to find the highest number in an array?

bash

Solution

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

Problem

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 ```

Original source

Related problems