I'm having a little issue, I can't go for bash v.4 I'm stick to use bash 3.2.57. I'm inputting my script in this form logs_logs_2017-04-{02..06}.tar.bz2 but since bash 3.2.57 doesn't support brace expansion with leading zeroes the script is feeded with the following logs_logs_2017-04-2.tar.bz2 logs_logs_2017-04-3.tar.bz2 ..... and these file names don't exist.

Any idea ?

Thanks !

marked as duplicate by Kusalananda, Anthony Geoghegan, terdon bash Apr 12 '17 at 9:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Go around the leading zero:

somecmd logs-0{2..9}.tar.bz2  logs-{10..15}.tar.bz2

(The 02..06 in the example is trivial to handle in this way.)

Or use printf:

somecmd $(printf "logs-%02d.tar.gz " {2..15})

That relies on word-splitting, and works only as long as the file name doesn't have glob characters or whitespace.

Properly done, this would be straightforward, but a bit long:

for x in {2..15} ; do
    files+=( "$(printf "logs-%02d.tar.gz" $x)" )
somecmd "${files[@]}"
  • Or use seq with a custom -f format string. – a CVn Apr 12 '17 at 9:10

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