Help with writing a script to run java commands in sequence in UNIX

Hi,

Brand new to these forums, and I hope that someone can help me out.

I'm trying to run the following command in UNIX

java -jar GenomeAnalysisTK.jar -T SplitSamFile -dt NONE -R reference.fa -I my.bam --outputRoot /my/path/SampleFiles/Sample_

It executes the SplitSamFile from GATK, but I want to run 3 additional commands, in a sequence. I can get them to run simultaneously but not in sequence, as I'm not able to pause the jobs (using ctrl + z) and put them in the background.

I've tried the following in my UNIX bash system (example with just two commands):

java -jar GenomeAnalysisTK.jar -T SplitSamFile -dt NONE -R reference.fa -I my1.bam --outputRoot /my/path/SampleFiles/Sample_ &; java -jar GenomeAnalysisTK.jar -T SplitSamFile -dt NONE -R reference.fa -I my2.bam --outputRoot /my/path/SampleFiles/Sample_ &

but this gives me the following error:

-bash: syntax error near unexpected token `;'

I've tried to consider doing a SH script, but can't figure out how to make the commands come in sequence rather than all starting at the same time.

Hope someone can help me out.

If you mean in sequence you don't need the ampersand. It's not clear what your intention is given the use of "in sequence" . The ampersand would when used correctly would run the command in a subshell.

<command> ; <command> ; <command>

Do you want to run all three in sequence, but all in the background?

If so, this syntax might help you.

( cmd1 ; cmd2 ; cmd3 ) &

You could also write it like this if it makes it clearer in your script:-

(
 cmd1
 cmd2
 cmd3
) &

Sorry if I've missed the point. Your query was a little vague.

Robin

1 Like

Thank you very much! This was just the solution I was looking for, sorry fvor being a bit vague.

Completely forgot about that way of using parentheses..