Highest value of given variables

Viewed 44

is it possible to somehow get the highest value of several variables?

For example i have

var1=10 var2=50 var3=48 var4=95 var5=41 var6=63

And i would like to store the highest value of these variables and store it to another variable.

3 Answers

How about writing the values through sort -n and using the last line to set the new variable?

var1 = 45
var2 = 23
var3 = 56
var4 = 29
var5 = 230
biggest = max(var1,var2,var3,var4,var5)
print(biggest)

Sure, the Unix shell can use programs like cat and grep, but it can also call python:

$ var1=10 var2=50 var3=48 var4=95 var5=41 var6=63
$ python -c "print(max($var1, $var2, $var3, $var4, $var5, $var6))"
95
$ max=$(python -c "print(max($var1, $var2, $var3, $var4, $var5, $var6))")
$ echo $max
95

Related