2

On Linux shell the result of echo -e "arrays2 2\narrays 2\narrays3 2" | sort is

arrays  2
arrays2 2
arrays3 2

and the result of echo -e "arrays2 28\narrays 28\narrays3 28" | sort is

arrays2 28
arrays 28
arrays3 28

Why in the second case the string arrays2 28 appears on first line. Is this a bug, or I miss something?

I tried this on RHEL4 and Ubuntu 11.04.

Thanks.

3
  • 1
    My sort doesn't behave like this. Commented May 3, 2011 at 11:04
  • Which distribution are you using? Commented May 3, 2011 at 11:06
  • Mine does. @MKo: what is your locale? Try echo $LANG Commented May 3, 2011 at 11:06

2 Answers 2

5

The behaviour is locale-dependent:

echo -e "arrays2 28\narrays 28\narrays3 28" | LANG=C sort

prints

arrays 28
arrays2 28
arrays3 28

While

echo -e "arrays2 28\narrays 28\narrays3 28" | LANG=de_DE.UTF-8 sort

prints

arrays2 28
arrays 28
arrays3 28

(Note that the locale must be installed for this to have this effect, if the locale doesn't exist, the behaviour will be the same as with LANG=C).

Sign up to request clarification or add additional context in comments.

Comments

2

If you change the locale from en_US.utf8 to the old default, it works the way you expect:

echo  -e "aaa\nfoo\narrays2 28\narrays 28\narrays3 28" | LC_ALL=C sort -
aaa
arrays 28
arrays2 28
arrays3 28
foo

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.