Ysiad Ferreiras
Ysiad Ferreiras

Reputation: 82

Using the sort command in BASH in osx 10.9.4

I'm running the following command in a bash shell, and the result is not sorted. Am I missing something obvious here?

ls /bin /usr/bin | grep -v '/bin:$'| grep -v '^$' | sort > proglist

Instead of a sorted list, the results are:

2to3
2to3-
2to3-2.7
2to32.6
BuildStrings
CpMac
DeRez
GetFileInfo
MergePef
MvMac
RSA_SecurID_getpasswd
ResMerger
Rez
RezDet
RezWack
SetFile
SplitForks
UnRezWack
[
a2p
a2p5.12
a2p5.16
addftinfo
afconvert
afhash
afida
afinfo
afmtodit
afplay
agentxtrap
agvtool
alias
allmemory
applesingle
appletviewer
apply
apr-1-config
...

Upvotes: 0

Views: 89

Answers (2)

Ross Ridge
Ross Ridge

Reputation: 39551

They're sorted in ASCII order. Numbers come before upper case letters, which come before lower case letters. Symbols and punctuation have various places in between and around them. You can try doing LC_COLLATE=en_US sort and see if it gives a better result.

Upvotes: 1

user3919556
user3919556

Reputation: 43

It looks like the results ARE sorted, but they're also separated by file type...in descending order: numbers > uppercase > symbols > lowercase.

I don't have enough experience using the command line to tell you how to fix it, but that's something I would look into before trying anything drastic :)

Upvotes: 1

Related Questions