11
$ touch file{1..12}

$ echo *e{1..12}
file1 file2 file3 file4 file5 file6 file7 file8 file9 file10 file11 file12

$ echo *{1..12}
file1 file11 file12 file2 file3 file4 file5 file6 file7 file8 file9 file10 file11 file12

I don't understand why this is happening. Please can someone explain?

21

Braces are not wildcard patterns. Check the documentation of bash expansions: braces are expanded very early in the process, and wildcard patterns are expanded in the last step¹.

Initially, the command consists of two words echo, *{1..12}. After brace expansion, the command contains 13 words: echo, *1, *2, …, *12. Then wildcard patterns are expanded. *1 expands to the list of file names ending in 1, which includes not only file1 but also file11 (which is sorted afterwards in lexicographic order). Likewise *2 expands to file12 and file2 (in this order). So you get echo, file1, file11, file12, file2, and then the other wildcards that matched a single file: file3, file4, …, file12.

¹ Next to last, if you follow the manual's description, but “quote removal” isn't really a thing — quotes are parsed earlier than the expansion process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.