shell script for the preprocessing step for all subjects

how can i creat the shell script in order to do the preprocessing step for all subjects of my resting-state analysis for 25 subject.
As shown in the attached picture.
than you


The most comprehensive example of this is AFNI_demos/AFNI_pamenc[/url], which we have presented during the more recent bootcamps as part of the [url=]CD/AFNI_demos.tgz package. That contains a complete set of scripts for running FreeSurfer, @SSwarper, and group analysis (3dttest++, including cases of -ETAC and -ClustSim).

There is a more recent example of processing scripts called APMULTI_Demo1_rest, which can be installed by simply running:


But while demonstrating options for processing multi-echo rest data, it does not contain anything to loop over subjects.

Both of those packages contain scripts for running on one’s desktop, or on an HPC system with swarming.

The scripts in APMULTI_Demo1_rest are what we currently base new analyses on, though again, to keep them simple, they do not loop over subjects.
The AFNI_pamenc scripts do loop over subjects, but they are not quite as nice as the APMULTI scripts.

In any case, please take a look and feel free to ask any questions about them.

  • rick

sorry but still do not know how can i creat the shell script As shown in the attached picture.
thank you


I don’t think there is anything particular about that shell script name—I guess that person wrote it however they wanted, and it contains their commands for analysis. This is not like a pre-packaged program.

You will have to decide what commands you want to run, and loop over the subjects and do that.

Are you familiar with shell scripting or Python?


Hello Osman,

I think what you are looking for is a so called “for loop”. The exact code for a “for loop” depends on the shell language that you are using (bash, tcsh, zsh, etc.).
A for loop can be created as follows.

Before the code that specifies AFNI proc, you would have to add the for loop code; something along the following lines:

for subject in Subject1 Subject2 Subject3 Subject4...

In the code above, you have to specifiy the exact folder names for your subjects. For example, if your subject folders are named “0050772, 0050773, 0050774”, then you have to change the subject names in the code above accordingly. Such as “subject1” in my example to “0050772”, and so on.

In a next step, you can define all the path names required for preprocessing the data, such as for the raw data, SSwarper results, and everything else needed. Here is an example:

directory_rest=/volumes/.../preprocessing_awake/restingstate/$subject # specifiy your resting-state functional runs path
directory_sswarper=/volumes/.../sswarper_anat1/$subject # specifiy SSwarper results

cd $directory_rest # tell your shell to cd (navigate) into the just assigned resting-state path

Finally, you can insert your AFNI proc script. Using the


symbol, you can link the specified paths above with AFNI proc, so that the latter knows where to find your data. \
-subj_id ${subject}_Rest \
-out_dir $directory_rest/Results \
-dsets \
	$directory_deoblique/Rest1_deoblique+orig \
-blocks despike tshift align tlrc volreg mask blur regress \
-copy_anat $directory_sswarper_1/anatSS.$subject.nii \
-tlrc_NL_warp \
-tlrc_NL_warped_dsets \
	$directory_sswarper/anatQQ.$subject.nii \
	$directory_sswarper/anatQQ.$subject.aff12.1D \
	$directory_sswarper/anatQQ.${subject}_WARP.nii \


AFNI proc will then start to preprocess your subjects, one after one.