In zsh, I get the expected result from both of these brace expansions:

$ touch file-{001..100}
$ touch file-{1..100}

The first one gives me files named file-001, file-002, etc., all the way to file-100. The second one gives me files named file-1, file-2, etc., all the way to file-100.

In bash, however, both give me files named file-1, file-2, etc. This strikes me as a pretty major bug (or design flaw) in bash's brace expansion.

Is there any way to configure bash to do the right thing in this case?

  • What version of bash are you working with? Works for me with $BASH_VERSION = 4.1.10(4)-release – glenn jackman Jul 14 '11 at 19:22
  • The server I tested this on uses returns himBH 3.00.16(1)-release from echo $- $BASH_VERSION. Locally I get himvBH 3.2.17(1)-release. Both expand to 1-100 instead of 001-100. – iconoclast Jul 14 '11 at 19:34

This is a bug in older versions of bash, fixed in bash 4.1 alpha. From the changelog:

mm. Fixed a bug that in brace expansion that caused zero-prefixed terms to not contain the correct number of digits.

| improve this answer | |
  • Was that bug fixed by Lumberg, by any chance? – l0b0 Jul 15 '11 at 8:10
  • @l0b0 I don't know; is the bash repository even public? And who's Lumberg and why would it matter who fixed the bug anyway? – Gilles 'SO- stop being evil' Jul 15 '11 at 9:38
  • Pop culture reference. Don't worry about it. – l0b0 Jul 15 '11 at 13:52

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.