Reputation: 329
I use a program called AFNI at work, and none of us are programmers, but we have enough knowledge to get by more often than not. Usually, when we have a lot of files we want to run AFNI on, we have to copy and paste the commands and edit the filenames in notepad before copying it into terminal, and this can elicit a number of mistakes. We are attempting to streamline this by using a shell script.
I am trying to run a foreach loop on a folder with .nii files in it, and I want those filenames to be appended to the end of the line that begins with '3dclustsim.' I want the filename to be put where $name is, so that the command is executed on that file.
So far, I have:
#!/bin/tcsh
clear
set path = ($path /home/lab/abin)
afni
foreach name (`*.nii`)
3dclustsim -fwhmxyz 16 16 16 -pthr 0.05 0.01 0.005 0.001 -athr 0.05 -nodec -iter 10000 -OKsmallmask -mask /home/lab/Desktop/Masks/$name
end
I have had no luck with any iteration of the above, or any modification I have found online. I am aware of the disdain many people have for C shells, but this program will only run in tcsh on a Unix/Linux/Mac machine in terminal.
If there is anything else I need to provide, please let me know.
Upvotes: 0
Views: 625
Reputation: 37298
You're on the right track.
Try adding/replacing this
cd /path/to/dir/with/nii_files
/bin/ls -l *.nii
foreach name ( * )
3dclustsim -fwhmxyz 16 16 16 -pthr 0.05 0.01 0.005 0.001 -athr 0.05 -nodec -iter 10000 -OKsmallmask -mask /home/lab/Desktop/Masks/$name
end
Your afni
program may be reading a config file that tells it where to put the files. You have to cd
to the correct directory to process them.
You may be doing that correctly, but that you get an error message *.nii : No Match
is telling you that the files you want to process aren't there.
However the confusing part of your question is that you have surrounded your *.nii
in back-quotes (in the for loop). Back-quotes mean "find the closing back-quote and then take the enclosed string and execute it as a command. If you really had no files in that dir, you should see something like
foreach name (`nonesuch`)
nonesuch : Command not Found.
But, that said, if you use the cd
and ls
, you can prove to yourself that you're in the right directory, and then the files should be procecssed.
Also, if you are creating this script with a windows editor, and then executing on Unix/Linux, you'll need to
dos2unix ./myScript.sh
chmod 755 ./myScript.sh
#then you can run it
./myScript.sh
IHTH
Upvotes: 1