I want to start off by distinguishing that Repeating command with different filenames is not what I am asking.
My question is, how do you build a single command with a directory of filenames in it, each prepended with the --thingy part of the command? In my specific application, I'm using GATK (though this question is about building the command line call), and even more specifically GenotypeGVCFs. My problem is that the command should look like:
java -jar GenomeAnalysisTK.jar \
-T GenotypeGVCFs \
-R reference.fasta \
--variant sample1.g.vcf \
--variant sample2.g.vcf \
-o output.vcf
but I have 93 variant files, and so the --variant line needs to be repeated 93 times, each with a different filepath. They're all in the same directory together, and they all have the same extension (*.g.vcf).
I've looked at doing something with find -exec + but couldn't think of a way to get the --variant attached to each result. xargs also seems promising, but I don't understand what it does super well, and so was having trouble setting it up. At this point, I might just have a Python script generate the command and then just paste it into the terminal, but I wanted to know if there's a "correct" way to do this for future.
--variantwhere I need the--variantbit to repeat for each thing in the glob.