Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So, I usually write/find a test case generator for any code that I write. This type of code generally leads to some file output. To be thorough, I try and generate many different files to test my code on.

Say the command is like this:

java test <parameters/> > <output filename/>

Is there a way to automate this for many different values of the parameters and generate many different files?

I tried:

for i in seq `0 3`; do java test $i > $i.txt; done

I wasn't able to use the $i in the filename, and without it the command gave me no errors, but did nothing else either. I know the Unix command line is very powerful, and I have a feeling that this should be possible, but I just don't know how to do it.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

If you're using Bash, there's no reason to use seq. Also, it's recommended that you use $() instead of backticks (but they're not needed either if you're using one of these forms).

for i in {0..3}; do java test $i > "$i.txt"; done

or

for ((i=0;i<=3;i++)); do java test $i > "$i.txt"; done
share|improve this answer

Assuming you are in the bash shell, just move the seq command into the backticks:

for i in `seq 0 3`; do java test $i > $i.txt; done
share|improve this answer
    
Your solution works as well, but I can select only one correct answer. –  efficiencyIsBliss Dec 7 '10 at 20:16

I would say make your app read stdin and spawn new threads, will be more efficient.

And yet another loop :

seq 0 3 | while read i; do java test $i > "$i.txt"; done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.