- 论坛徽章:
- 16
|
Following comment from http://stackoverflow.com/questio ... es-it-work-internal
From help test:
STRING1 > STRING2
True if STRING1 sorts after STRING2 lexicographically.
Internally, bash either uses strcoll() or strcmp() for that:
else if ((op[0] == '>' || op[0] == '<') && op[1] == '\0')
{
if (shell_compatibility_level > 40 && flags & TEST_LOCALE)
return ((op[0] == '>') ? (strcoll (arg1, arg2) > 0) : (strcoll (arg1, arg2) < 0));
else
return ((op[0] == '>') ? (strcmp (arg1, arg2) > 0) : (strcmp (arg1, arg2) < 0));
}
The latter actually compares ASCII codes, the former (used when locale is enabled) performs a more specific comparison which is suitable for sorting in given locale.
|
|