Link to home
Start Free TrialLog in
Avatar of Edgar Cole
Edgar ColeFlag for United States of America

asked on

Comparing Korn Shell Variables

Is there a simple way to compare the value of two Korn shell variables, and when the value of the second is larger, assign that value to the first? So, if the value of VAR2 is greater than the value of VAR1, set VAR1 equal to VAR2.
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

For a numeric comparison:

[[ $VAR2 -gt $VAR1 ]] && VAR1=$VAR2

For a string comparison:

[[ "$VAR2" > "$VAR1" ]] && VAR1="$VAR2"

"man test" explains all test operators.
Avatar of Edgar Cole

ASKER

Yep, that would do it. Do I feel stupid. I guess I was just feeling lazy today. :-)
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial