Case-Sensitive GNU sort

GNU sort appears to be producing case-insenstive output all the time, no matter what you use for the case-insenstive switch. Turns out there’s a little more going on behind the scenes you need to know.

Had something unexpected happen while using sort the other day: it behaved differently on two different systems.

In a nutshell, I went to go sort data that looked like this:
xyz
CAT
abc

The correct answer, due to case-sensitifivity, should have been:
CAT
abc
xyz

This, by the way is what Cygwin happens to produce.

Instead I was getting the case-insensitve answer:
abc
CAT
xyz

And while the sort program had a case-insenstivive switch, -f, it always seemed to be applied.

I checked for a command alias. None.

I tried a negation value, -f-, and that did nothing for me.

Eventually I figured out that the issue was with the locale specified in the environment variables.

If LC_ALL=en_US, then I got a case-insentive order, no matter what. The solution was to change it to LC_ALL=C to get the case-sensitive version.

As GNU allows explicitly for case-insensitivity, I really wish they’d also explicitly allow for case-sensitivy.

This seems to trip up a lot of people, judging by the number of posts out there about it.