문제

I'm trying to run a script in the terminal but I am getting the error message that the foreach command is not found. I've been trying to find an answer online for the past 6 hours but I can't seem to find anything. Can you please let me know why this is out-putting ' line 20: foreach: command not found'?

Script Here:

#!/bin/csh
# Source name: fa_extract
# Author name: ----
# Last modified by: Apr 29, 2013
# Date modified: Apr 29, 2013
# Program description: extract FA, AD, RA values
# Main function: extract FA, AD, RD, MD, into txt files
# Variable description: age; wt, waytotal


echo "# Source name: fa_extract"
echo "# Author name: ----"
echo "# Last modified by: Apr 29, 2013"
echo "# Date modified: Apr 29, 2013"
echo "# Program description: extract FA, AD, RA values"
echo "# Main function: extract FA, AD, RD, MD, into txt files"
echo "# Variable description: age; wt, waytotal"

#1st level
foreach sub$(01_007_c/01_007_c_L 01_007_c/01_007_c_R 01_012_c/01_012_c_L 01_012_c/01_012_c_R 01_013_c/01_013_c_L 01_013_c/01_013_c_R 01_014_c/01_014_c_L 01_014_c/01_014_c_R 01_015_c/01_015_c_L 01_015_c/01_015_c_R 01_029_p/01_029_p_L 01_029_p/01_029_p_R 01_035_p/01_035_p_L 01_035_p/01_035_p_R 01_036_p/01_036_p_L 01_036_p/01_036_p_R 01_037_p/01_037_p_L 01_037_p/01_037_p_R 01_038_p/01_038_p_L 01_038_p/01_038_p_R 01_040_p/01_040_p_L 01_040_p/01_040_p_R 01_041_p/01_041_p_L 01_041_p/01_041_p_R 01_042_p/01_042_p_L 01_042_p/01_042_p_R 01_043_p/01_034_p_L 01_043_p/01_043_p_R 01_044_p/01_044_p_L 01_044_p/01_044_p_R 01_045_p/01_045_p_L 01_045_p/01_045_p_R 01_046_p/01_046_p_L 01_046_p/01_046_p_R)

cd ~/Desktop/OBI_pre_process/DTI/Tractography/SLF/${sub}/

echo "----------------------------------------------------------------------------------------------------------"
pwd


set wt=`cut -f2 -d '' waytotal`#normalization by waytotal
echo "waytotal = $wt"
fslmaths fdt_paths.nii.gz -div $wt fdt_paths_fa_norm.nii.gz 
fslmaths fdt_paths_fa_norm.nii.gz -thrP 40 -bin fdt_paths_fa_bin.nii.gz # threshold by thrP40 & binarize

fslmaths *_DTI_FA.nii.gz -mas fdt_paths_fa_bin.nii.gz fa_masked.nii.gz # masking FA maps...................FA
fslstats fa_masked.nii.gz -M > fa.txt

fslmaths *_DTI_L2.nii.gz -mas fdt_paths_fa_bin.nii.gz L2_masked.nii.gz # masking L maps..................RD
fslmaths *_DTI_L3.nii.gz -mas fdt_paths_fa_bin.nii.gz L3_masked.nii.gz
fslmaths L2_masked.nii.gz -add L3_masked.nii.gz L2_L3_masked.nii.gz
fslmaths L2_L3_masked.nii.gz -div 2 rd.nii.gz
fslstats rd.nii.gz -M > rd.txt

fslmaths *_DTI_L1.nii.gz -mas fdt_paths_fa_bin.nii.gz ad.nii.gz # masking L maps..................AD
fslstats ad.nii.gz -M > ad.txt

fslmaths *_DTI_MD.nii.gz -mas fdt_paths_fa_bin.nii.gz md.nii.gz # masking L maps..................MD
fslstats md.nii.gz -M > md.txt

end # <<<<<<<<<subject loop ends
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>1st level done" 

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~2nd level

rm -rf /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/fa/athletes*.txt
rm -rf /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/fa/controls*.txt


# athletes
foreach sub$(01_007_c/01_007_c_L 01_007_c/01_007_c_R 01_012_c/01_012_c_L 01_012_c/01_012_c_R 01_013_c/01_013_c_L 01_013_c/01_013_c_R 01_014_c/01_014_c_L 01_014_c/01_014_c_R 01_015_c/01_015_c_L 01_015_c/01_015_c_R 01_029_p/01_029_p_L 01_029_p/01_029_p_R 01_035_p/01_035_p_L 01_035_p/01_035_p_R 01_036_p/01_036_p_L 01_036_p/01_036_p_R 01_037_p/01_037_p_L 01_037_p/01_037_p_R 01_038_p/01_038_p_L 01_038_p/01_038_p_R 01_040_p/01_040_p_L 01_040_p/01_040_p_R 01_041_p/01_041_p_L 01_041_p/01_041_p_R 01_042_p/01_042_p_L 01_042_p/01_042_p_R 01_043_p/01_034_p_L 01_043_p/01_043_p_R 01_044_p/01_044_p_L 01_044_p/01_044_p_R 01_045_p/01_045_p_L 01_045_p/01_045_p_R 01_046_p/01_046_p_L 01_046_p/01_046_p_R)

cd /Desktop/OBI_pre_process/DTI/Tractography/SLF/${sub}/
cat             fa.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/athletes_fa.txt
cat             rd.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/athletes_rd.txt
cat             ad.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/athletes_ad.txt
cat             md.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/athletes_md.txt
#cat            ../age.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/athltes_age.txt
cat           ../seg_0.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/athletes_seg_0.txt
cat               ../seg_1.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/athletes_seg_1.txt
cat               ../seg_2.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/athletes_seg_2.txt

end
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>2nd level athletes done" 

# controls
foreach sub$(01_007_c/01_007_c_L 01_007_c/01_007_c_R 01_012_c/01_012_c_L 01_012_c/01_012_c_R 01_013_c/01_013_c_L 01_013_c/01_013_c_R 01_014_c/01_014_c_L 01_014_c/01_014_c_R 01_015_c/01_015_c_L 01_015_c/01_015_c_R 01_029_p/01_029_p_L 01_029_p/01_029_p_R 01_035_p/01_035_p_L 01_035_p/01_035_p_R 01_036_p/01_036_p_L 01_036_p/01_036_p_R 01_037_p/01_037_p_L 01_037_p/01_037_p_R 01_038_p/01_038_p_L 01_038_p/01_038_p_R 01_040_p/01_040_p_L 01_040_p/01_040_p_R 01_041_p/01_041_p_L 01_041_p/01_041_p_R 01_042_p/01_042_p_L 01_042_p/01_042_p_R 01_043_p/01_034_p_L 01_043_p/01_043_p_R 01_044_p/01_044_p_L 01_044_p/01_044_p_R 01_045_p/01_045_p_L 01_045_p/01_045_p_R 01_046_p/01_046_p_L 01_046_p/01_046_p_R)# >>>>>>>>>subject loop

cd /Desktop/OBI_pre_process/DTI/Tractography/SLF/${sub}/
cat             fa.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/controls_fa.txt
cat             rd.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/controls_rd.txt
cat             ad.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/controls_ad.txt
cat             md.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/controls_md.txt
#cat            ../age.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/controls_age.txt
cat           ../seg_0.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/controls_seg_0.txt
cat           ../seg_1.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/controls_seg_1.txt
cat           ../seg_2.txt >> /Desktop/OBI_pre_process/DTI/Tractography/SLF/2nd_level/thrP40/N21_17/controls_seg_2.txt

end
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>2nd level controls done" 
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>ALL DONE !" 
도움이 되었습니까?

해결책

Reason its failing because csh has foreach loop no other shell does. so if you try to execute the script by anyother shell it will fail.

since you already have #!/bin/csh you can execute the script using ./scriptname but if you are intended to execute it within someother shell------

replace for each line with following

for sub in $(echo "all the strings seperated by a space")
 do 

 \# rest of your script inside for should come here

done         #done is replacing end in your case

if you cannot use echo "string SEPERATED by spaces" then you can use cut with the delimeter you have.

I am not able to figure our delimeter you are using in foreach statement.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top