You are not logged in.
Is it possible to have a bash script pick the highest and lowest values of four variables? I've been googling for this but haven't come up with anything. I have a script that assigns variables ($c0, $c1, $c2, and $c3) based on the coretemps from grep/sed statements of sensors. I'd like to also assign two new variables ($chigh and $clow) that will be the highest and lowest of the original four but I don't know how to go about it in bash.
Thanks!
Last edited by graysky (2009-11-25 09:03:36)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
> a=10
> b=20
> (( a < b )) && echo $a || echo $b
10
> b=5
> (( a < b )) && echo $a || echo $b
5
Offline
Building up from Allan's for four
highest=0
lowest=999
for value in 40 100 20 80; do (( value < lowest )) && lowest=$value; (( value > highest )) && highest=$value; done
echo HIGH: $highest
echo LOW: $lowest
Offline
Thanks guys.
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
just for shits and giggles
LC_ALL=C range=( $( (for value in 40 100 20 80; do echo $value; done) | sort -n ) )
echo HIGH: ${range[${#range[@]}-1]}
echo LOW: ${range[0]}
//github/
Offline