I want a simple testing shell script that launches a program N times in parallel, and saves each different output to a different file. I have made a start that launches the program in parallel and saves the output, but how can I keep only the outputs that are different? Also how can I actually make the echo DONE! indicate the end?
#!/bin/bash
N=10
for((i=1; j<=$N; ++i)); do
./test > output-$N &
done
echo DONE!
You’ll want to use the wait builtin.
You could specify your jobs as
%1,%2, …:but as long as you have no other child processes, you can just use it with no arguments; it’ll then wait for all child processes to finish:
Your separate question, how to keep only different outputs, is a little trickier. What exactly do you mean – different from what? If you have a baseline, you could do this:
If you want to keep all unique outputs, the algorithm’s a little more complex, obviously, but you could still use
diff -qto test for identical output.