I've parallelized a for cycle in bash using GNU Parallel. This is a very simple example to show what I want to reach:
seq 10 | parallel -n0 echo "Hello World" &
I would like to detach from terminal all the run, except the last one, thus removing the & only in the last cycle. Is there a way to do this?
EDIT: Since I was not very clear, I'll try to explain myself in a better way:
I have a simulator starting, then with GNU parallel I launch many times the same script that connect with the simulator. I want all of them detaching from the terminal except the last one to avoid confusion with overlapping output.
There is no option for that, but default is that the first job gets /dev/tty as input. So maybe you can run your last job first?
If you just want the output and not the input then this should work:
seq 10 | parallel echo Hello World '> {= $_= $job->seq() == total_jobs() ? "/dev/tty" : "/dev/null" =}'
(Requires version 20160122 or newer)
Otherwise a workaround is to save to files and output the last file:
seq 10 | parallel --files -n0 echo Hello World | tail -n1 | parallel -u cat