I have two sets of files organized as such:

#first directory


In this directory, I have 242 files in total. My current nested command to run script.py is below:

for z in `seq 0 10`; do
for i in `seq 1 22`; do python script.py --l2 --ld-wind-cm 1 --annot  file${z}.${i} --thin-annot --out  file${z}.${i} --print-snps;done;done

If you notice, I have hardcoded file in this loop. Is there a way to run this without using file${z}.${i} and instead using a variable?

  • This stopped being the same question when you brought a second directory into it. Having it there pretty much invalidates the existing answers. Please, write your questions so that they include all the necessary detail.
    – ilkkachu
    Dec 16, 2018 at 18:04
  • Ok, I'll make a new question instead. Thanks.
    – Workhorse
    Dec 16, 2018 at 18:12

2 Answers 2


Your request is not quite clear. Why the two loops across the two ranges? Wouldn't

for FN in *.tar.gz; do echo python script.py --out "$FN"; done

be sufficient? Remove the echo if happy with the result.

If there is NO other file than the ones you want to work upon, the "extensions" can go away as well, run the for loop across *.

  • Hi, I have clarified my question, if that is ok?
    – Workhorse
    Dec 16, 2018 at 1:23

If there are other tar.gz files there besides those files you need you can use:

for i in file{0..10}.{1..22}.tar.gz; do python script.py --out "$i" --print-file; done

If these are the only files in the folder then this is sufficient, and will work with any file name.

for i in * ; do python script.py --out "$i" --print-file; done

If these are the only tar.gz files in folder, but there are some other type of files there then this can be used and can work with any name of tar.gz files:

for i in *.tar.gz ; do python script.py --out "$i" --print-file; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .