I would expect bash sort to compare strings like this:
- Start at the first char (of both strings)
- If the chars are equal, proceed to the next char
- If they are unequal, return greater/lesser result to sort algorithm
- If there are no more chars, return equals
For some reason, it seems like this is not a case.
Let's take the following input:
a
b
.
-
This is sorted by bash sort as
-
.
a
b
Now, for input
b.de
bb.de
I would expect the following sort result:
b.de
bb.de
Because the first char is equal, and for the second char, .
comes before b
(as seen in the first test).
For some reason, this is not the case, the strings are sorted like this:
bb.de
b.de
Why is sort
behaving this way, and is there a way to make it behave "as expected"?
I have tested the same examples with python, and python sorts as expected.