Reply To: multiple bdp.sh commands in bash

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

#1579
David Shattuck
Keymaster

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/bdp.sh ${SubjID}.bfc.nii.gz --nii ${SubjID}.dwi.nii.gz -g ${SubjID}.bvec -b ${SubjID}.bval
done

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:

#!/bin/bash
for SubjID in $@; do
	/Applications/BrainSuite18a/bdp/bdp.sh ${SubjID}.bfc.nii.gz --nii ${SubjID}.dwi.nii.gz -g ${SubjID}.bvec -b ${SubjID}.bval
done

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

runBDPsubjs.sh 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