0

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 !

DaWe4444
  • 113
  • 1
  • 11

1 Answers1

1

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:

files=()
for x in {2..15} ; do
    files+=( "$(printf "logs-%02d.tar.gz" $x)" )
done
somecmd "${files[@]}"
ilkkachu
  • 133,243
  • 15
  • 236
  • 397