Previous: , Up: Typing and Comparison   [Contents][Index]


6.3.2.3 String Comparison With POSIX Rules

The POSIX standard says that string comparison is performed based on the locale’s collating order. This is usually very different from the results obtained when doing straight character-by-character comparison.35

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

Footnotes

(35)

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