Strange sort behavior compared to linux

Hi everyone,

we found a strange behavior, that we can't explain atm. On a FreeBSD 10.2 we get this using sort:

[root@FBSD /]# setenv LC_ALL de_DE.UTF-8
[root@FBSD /]# sort test.list

which is just an wrong order in our findings.

On a linux (older redhat) this comes up sorting the same list:

[root@LINUX /]# export LC_ALL=de_DE.utf8
[root@LINUX /]# sort test.list

which looks just correct.
The same happens when using sort functions in e.g. PHP.

Any help would be really appreciated as this seems to be a serious problem, if sorting fails at OS level. But maybe we just blind and someone could shed a light!

Many thanks in advance!
Can you point out any reference as to what the proper sorting order for german language is? To me it looks like the FreeBSD implementation uses just character code values and both 'Ö' and 'Ä' have character code values greater than any of the ASCII characters.

Edit: I believe the difference is in decomposition of the 'Ö' and 'Ä' characters. There are two ways to read in them in Unicode, either as single characters 'Ö' and 'Ä' or composites 'O' + '¨' and 'A' + '¨'.
The sorting works fine here (and it's correct as per OP), just checked it.
What I see is that if a locale does not exist, csh just silently does what the OP describes, but bash complains about missing locale.
icecoke , have you checked if you have such locale in /usr/share/locale/?

Citation from wiki (

  • In German letters with umlaut (Ä, Ö, Ü) are treated generally just like their non-umlauted versions; ß is always sorted as ss. This makes the alphabetic order Arg, Ärgerlich, Arm, Assistent, Aßlar, Assoziation. For phone directories and similar lists of names, the umlauts are to be collated like the letter combinations "ae", "oe", "ue" because a number of German surnames appear both with umlaut and in the non-umlauted form with "e" (Müller/Mueller). This makes the alphabetic order Udet, Übelacker, Uell, Ülle, Ueve, Üxküll, Uffenbach.
There is a DIN5007 v2 which is specially for lists, that is shown in - so like the order example in the english wiki citiation above.

So my linux example from the first post seems to be wrong, too. This kind of sorting seems to be more common in austria and does not follow any DIN standard.

EDIT: trying it on linux with different words, it comes out it is the DIN5007 v1 not the austrian order.


Could you copy your output here? And what env you used?

The locale files are existing on the server. Same output with bash as tested before.

Is there a way to modify this ordering? Maybe by creating an own locale dir?
Her is my output (I'm on FreeBSD 11-CURRENT though):
root@dendrobates:~ # setenv LC_ALL de_DE.UTF-8
root@dendrobates:~ # sort /tmp/test.list
aragats Thanks! I just installed a vanilla 10.2 RELEASE and it failed again - so no latter settings that killed that. Will set up 10.3 + 11 to check if this was changed between these releases. I will follow up here.
I confirm it does not work properly in FreeBSD 10.3.
icecoke , see the difference between locales in different builds:
FreeBSD 10.3:
root@freebsd10:~ # ls -l /usr/share/locale/de_DE.UTF-8/
total 8
lrwxr-xr-x  1 root  wheel  28 25 Mär 02:18 LC_COLLATE -> ../la_LN.US-ASCII/LC_COLLATE
lrwxr-xr-x  1 root  wheel  17 25 Mär 02:18 LC_CTYPE -> ../UTF-8/LC_CTYPE
lrwxr-xr-x  1 root  wheel  30 25 Mär 02:18 LC_MESSAGES -> ../de_DE.ISO8859-1/LC_MESSAGES
-r--r--r--  1 root  wheel  36 25 Mär 02:18 LC_MONETARY
lrwxr-xr-x  1 root  wheel  29 25 Mär 02:18 LC_NUMERIC -> ../de_DE.ISO8859-1/LC_NUMERIC
-r--r--r--  1 root  wheel  370 25 Mär 02:18 LC_TIME
FreeBSD 11:
root@dendrobates:~ # ls -l /usr/share/locale/de_DE.UTF-8/
total 11
lrwxr-xr-x  1 root  wheel  25 13 Mai  07:07 LC_COLLATE -> ../en_US.UTF-8/LC_COLLATE
lrwxr-xr-x  1 root  wheel  23 13 Mai  07:07 LC_CTYPE -> ../en_US.UTF-8/LC_CTYPE
-r--r--r--  1 root  wheel  148 13 Mai  07:07 LC_MESSAGES
lrwxr-xr-x  1 root  wheel  26 13 Mai  07:07 LC_MONETARY -> ../sl_SI.UTF-8/LC_MONETARY
lrwxr-xr-x  1 root  wheel  25 13 Mai  07:07 LC_NUMERIC -> ../tr_TR.UTF-8/LC_NUMERIC
-r--r--r--  1 root  wheel  409 13 Mai  07:07 LC_TIME
aragats Yep - found the same here. And if you make a head into the files, you see they have different formats:

[root@tulobu ~]# head /usr/share/locale/la_LN.US-ASCII/LC_COLLATE

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™šžŸ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ðñòóôõö÷øùúûüýþÿ

root@fbsd11:~ # head /usr/share/locale/en_US.UTF-8/LC_COLLATE
BSD 1.0
"…ÿÿ-Iÿÿÿ      !

 (,8&B97+-.4 <  $*5-I.J/K0L1M2N3O4Q5R6S

So - does anyone has an idea HOW these files are created? So that maybe I'm in the position to convert/create one single LC_COLLATE file that respects the correct sorting in <11.0 ?
Well, since LC_COLLATE is a symlink, instead of creating another one, you can simply change it to point to the same original file as in FreeBSD 11. i.e. ../en_US.UTF-8/LC_COLLATE.
aragats I would, if this would exist. It is just a symlink to the same target in 10.2/3 - so no correct LC_COLLATE to find:

[root@tulobu ~]# ll /usr/share/locale/en_US.UTF-8/
total 10
drwxr-xr-x    2 root  wheel    8 26 Jan  2014 ./
drwxr-xr-x  176 root  wheel  176 26 Jan  2014 ../
lrwxr-xr-x    1 root  wheel   28 26 Jan  2014 LC_COLLATE@ -> ../la_LN.US-ASCII/LC_COLLATE

In the meantime I found the tool that seems to be used to create LC_COLLATE files: colldef - so I guess I need find the .src files somewhere in the base system, too ;)
Not sure how much the effort will be for this.
So, in the meantime I tried around a lot and find out, how the LC_COLLATE files in FreeBSD <11.0 are build and which sources used for it.

The problem is, that the 'old' colldef() does not support multibyte signs completely. E.g the substitution needed for e.g. DIN5007v2 is not possible with multibyte.

What I did now is to create a colldef source file for the ISO8859-15 character set, which handles UTF-8 input, so that it is able to order such chars. In the result it is 'nearly' an DIN5007v1 order except that ß is not substituted with 'ss' but just handled as an single, small 's'. Just an small issue in the german language.

So if someone with FreeBSD 10.x want's to get near to the correct collation of FreeBSD 11.x and DIN5007v1 than use this source to create your own UTF-8 LC_COLLATE file:

# ISO8859-15/UTF-8 (ISO8859-15 character set)
# order (DIN5007v1 like) for characters from the ISO8859-15 set in unicode to be used in FreeBSD <11.0
# no map used
# $FreeBSD: colldef/de_DE.UTF-8.pre11.src james t. koerting $
# substitution for ISO8859-15 input only - DIN5007 v1 + v2
substitute \xdf with "ss"
# v2 Order - ISO8859-15 input only. So disable it.
#substitute \xc4 with "Ae"
#substitute \xd6 with "Oe"
#substitute \xdc with "Ue"
#substitute \xe4 with "ae"
#substitute \xf6 with "oe"
#substitute \xfc with "ue"

order \
# controls
#        <NU>;...;<US>;<PA>;...;<AC>;\
#        <NS>;           <SP>;!;   <!I>;           \";  <<<>;           </>/>>;         <Nb>;\
#        EUR;            <Ct>;           <DO>;<Pd>;           <Ye>;\
#        %;&;';\(;\);*;+;<+->;         <-:>;           <*X>;           \,;  <-->;           -;   .;   /;\
# digits
#        0;(1,<1S>);         (2,<2S>);         (3,<3S>);         4;...;9;\
#        :;\;;\<;=;>;?;<?I>;           <SE>;           <PI>;           <Co>;           <Rg>;           <At>;\
# capital
#        (A,   <A'>,<A!>,<A/>>,<AA>,<A?>);                                            (<A:>,<AE>);\
#        B;   (C,   <C,>);         (D,   <D->);         (E,   <E'>,<E!>,<E/>>,<E:>);\
#        F;   G;   H;   (I,   <I'>,<I!>,<I/>>,<I:>);\
#        J;   ...;M;   (N,<N?>);            (O,   <O'>,<O!>,<O/>>,<O?>,<O//>,<O:>,<OE>);\
#        P;   ...; R;   (S,   <S<>);         T;   (U,<U'>,<U!>,<U/>>,<U:>);\
#        V;   W;   X;   (Y,   <Y'>,<Y:>);                  (Z,   <Z<>);\
#        <TH>;\
#        [;\\;];^;_;   <'m>;`;\
# small
#        (a,   <a'>,<a!>,<a/>>,<aa>,<a?>,<a:>,<ae>)\
#        b;   (c,   <c,>);         (d,   <d->);         (e,   <e'>,<e!>,<e/>>,<e:>);\
#        f;   g;   h;   (i,   <i'>,<i!>,<i/>>,<i:>);\
#        j;   ...;m;   (n,   <n?>);         (o,   <o'>,<o!>,<o/>>,<o?>,<o//>,<o:>,<oe>);\
#        p;   ...; r;   (s,   <s<>);                  t;   (u,   <u'>,<u!>,<u/>>,<u:>);\
#        v;   w;   x;   (y,   <y'>,<y:>);(z,   <z<>);\
#        <th>;\
#        \{;  <NO>;           |;   \};  ~;   <.M>;           <DG>;           <My>;           <DT>;\
# remains
#        <-a>;<-o>

I'm sure I might missed something here or did a mistake in trying to create the DIN5007v1 order - so just drop me a diff or something if you find a failure.