Reply To: multiple commands in bash

Forums Forums BrainSuite Diffusion Pipeline (BDP) multiple commands in bash Reply To: multiple commands in bash

David Shattuck

hi Dahyun –

I don’t know why the semicolon isn’t working — the bash shell should be separating them into separate commands. It looks like you are only using one dash for the –nii flag, though. That could just be how our forum software translated it into text (it sometimes converts two dashes into a single emdash).

In any case, for multiple subjects, I would typically use a for loop, like this:

for SubjID in subj1 subj2 subj3; do
	/Applications/BrainSuite18a/bdp/ ${SubjID}.bfc.nii.gz --nii ${SubjID}.dwi.nii.gz -g ${SubjID}.bvec -b ${SubjID}.bval

For this, you only type the BDP command once, and you can add subjects to the for loop as you like. If you put this in a bash script, you can reuse it, something like:

for SubjID in $@; do
	/Applications/BrainSuite18a/bdp/ ${SubjID}.bfc.nii.gz --nii ${SubjID}.dwi.nii.gz -g ${SubjID}.bvec -b ${SubjID}.bval

If you save that into a file, let’s say, make it executable (using chmod +x, then you can run it from the command line and pass it the subject IDs that you want to process, e.g., subj1 subj2 subj3

It will run the commands you are trying to call. The $@ in the script contains the arguments that you passed to the script on the command line.

Hope that helps.

-David Shattuck