Previous: , Up: Typing and Comparison   [Contents][Index] String Comparison with POSIX Rules

The POSIX standard says that string comparison is performed based on the locale’s collating order. This is the order in which characters sort, as defined by the locale (for more discussion, see Locales). This order is usually very different from the results obtained when doing straight character-by-character comparison.34

Because this behavior differs considerably from existing practice, gawk only implements it when in POSIX mode (see Options). Here is an example to illustrate the difference, in an en_US.UTF-8 locale:

$ gawk 'BEGIN { printf("ABC < abc = %s\n",
>                     ("ABC" < "abc" ? "TRUE" : "FALSE")) }'
-| ABC < abc = TRUE
$ gawk --posix 'BEGIN { printf("ABC < abc = %s\n",
>                             ("ABC" < "abc" ? "TRUE" : "FALSE")) }'
-| ABC < abc = FALSE



Technically, string comparison is supposed to behave the same way as if the strings were compared with the C strcoll() function.