2

I understand that it is a string comparison, however i dont understand how "abc" & "123" are compared against each other. Thanks in advance!

Ashlyn
  • 31
  • 3

1 Answers1

7

That's because, inside [[…]], the operators < and > do string comparison.

In doing an string comparison the order is given (basically) by the alphabet, where a is before (smaller) than b and smaller than c: a < b < c.
Numbers are usually before (smaller) than letters: 1 < 2 < a

So, as an a sorts after a 1 abc is greater than 123:

$ [[ abc > 123 ]] && echo yes
yes

Or, as you present it:

$ x=abc    y=123
$ [[ $x > $y ]] && echo yes
yes
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250