0

I am trying to write a script that takes a parameter from the cli and uses that number as a top limit in a range for creating a number of files.

num_files=$1
time parallel -N 10 'cat source.txt | tee copy{1}.txt copy{2}.txt copy{3}.txt copy{4}.txt copy{5}.txt copy{6}.txt copy{7}.txt copy{8}.txt copy{9}.txt copy{10}.txt' ::: {1..$numfiles}

I've tried every type of quoting I can think of but, oddly, the only output I get is a single file named copy{1..200}.txt (if I pass in 200). So the number I pass in is getting picked up correctly, its just not working as I'd expect.

Is this possible?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
MeanwhileInHell
  • 6,780
  • 17
  • 57
  • 106
  • `{1..$numfiles}` does now work as expected, brace expansion happens before variable does... see this [link](https://mywiki.wooledge.org/BashPitfalls#for_i_in_.7B1...24n.7D) at least in `bash` – Jetchisel Mar 30 '23 at 08:44
  • 1
    You could use `seq` to generate your numbers. See _man seq_. – user1934428 Mar 30 '23 at 09:03
  • See the last script in https://stackoverflow.com/a/56836378/1745001 for how to use `seq` to generate multiple strings that you could use as file names. – Ed Morton Mar 30 '23 at 12:53
  • Great, `seq` worked as I'd hoped. Thanks a lot! – MeanwhileInHell Mar 30 '23 at 14:08

0 Answers0