0

I'm writing a bash script to download a BUNCH of data files from a source. The data files all have a numeric portion of their filename to identify their segment, like so: Filename_blahblah_000000 or Filename_blahblah_000024, etc.

I want to open multiple threads, so I can pull these segments in parallel (there are roughly 4200 of them).

Here's my question: Is there any way I can pass input parameters that I can invoke in a for loop? Sample code is below.

Here's the code in "brute force" format. This particular example would pull 3 files: File 000000, file 000001 and file 000002, called as follows:

sr/bin/env bash
(initial non-related stuff)

for i in {0..2}
do
    filenum="00000$i"

    ...blahblahblah

done

And here's the result:

% ./data_download-19-x.sh <-- This is the code entered into the command line

Downloading file /blah/file_000000...
(stuff happens)
Downloading file /blah/file_000001...
(stuff happens)
Downloading file /blah/file_000002...
(stuff happens) (done, everybody happy)

However, I want to be able to pass in the start and end parameters, so the code now looks like this:

#!/usr/bin/env bash
(initial non-related stuff)

start=$1
end=$2

for i in {@start..@end} <-- I KNOW THIS IS WHERE THE WRONGNESS IS
do
    filenum="00000$i"

    ...blahblahblah

done

Except now, the end result looks like this:

% ./data_download-19-x.sh 0 2 <-- Notice the 2 input parameters

Downloading file /blah/file{0..2}

Error: Program failed.
Exception: File not found

It's interpreting the iterative parameter as the literal string {0..2} instead of processing $start and $end as numbers.

So is there a sneaky way to make bash interpret the values of $start and $end as the bounds of this for loop, or do I have to make a bunch of different files with the bounds hard-coded into them and execute them that way?

0 Answers0