Shell: Wildcards guarantee alphabetical order?

When I have files a.txt

, b.txt

and c.txt

, it is guaranteed that

cat *.txt > all_files.txt

      

or

cat ?.txt > all_files.txt

      

will combine files alphabetically?

(Alphabetic order was preserved in all my tests, but I'm not sure because, for example, with the ls

order is undefined and does not have to be alphabetical, but this often happens because files were often written to a directory in alphabetical order)

+3


source to share


1 answer


No, it depends on the language. The order is dictated by the sort order in the locale, which can be changed using environment variables LC_COLLATE

or LC_ALL

. Note that bash behaves differently in this regard to some other shells (like the Korn shell).

If your locale is set to C

or POSIX

, it will be installed in character set order. Otherwise, you will probably notice the difference with mixed lettering, for example. the sequence for en_ locales is aAbBcC ... xXyYzZ. For example see http://collation-charts.org/fc6/fc6.en_GB.iso885915.html .



The available locales can be listed with locale -a

.

Edit: There is another variable available LANG

, but not usually used these days. According to the Single UNIX specification, it is used: in the absence of LC_ALL and other LC_ * ... variables.

+5


source







All Articles