bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sort command doesn't sort '@' character correctly


From: Greg Wooledge
Subject: Re: Sort command doesn't sort '@' character correctly
Date: Thu, 20 May 2021 14:09:53 -0400

On Thu, May 20, 2021 at 04:43:49PM +0000, Michael Jensen wrote:
> Repeat-By:
> 
>         echo "xxaxxon" > test.txt
>         echo "@zorg" >> test.txt
>         echo "@jupiterlander" >> test.txt
>         cat test.txt | sort
> 
>         Note it prints out:
> 
>         @jupiterlander
>         xxaxxon
>         @zorg
> 
>         Expected:
> 
>         @jupiterlander
>         @zorg
>         xxaxxon

The sort command is not part of bash; it's part of your operating system.
If you believe it's misbehaving for your locale, you should file a bug
report with your operating system vendor.

However, it's possible that this is "working as intended" for your locale,
which is a thing that -- once again -- your operating system vendor has
decided.  The behaviors of locales tend to be pretty arbitrary and
surprising.

If you want strict ASCII-based sorting, with no characters ignored, then
you should use the "POSIX" or "C" locale setting.  For example:

unicorn:~$ printf '%s\n' xyz @zorg @jupiter | sort
@jupiter
xyz
@zorg
unicorn:~$ printf '%s\n' xyz @zorg @jupiter | LC_COLLATE=POSIX sort
@jupiter
@zorg
xyz

Hope this helps.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]