你有两个错误:
主要问题是 for 命令,变量$filename
包含*
而不是真实文件名。你应该使用文件名$(find . -name "*");do
第二个是这样的:
您必须确定变量的$filename
值,即在我的 bash shell 中,文件名输出是
./b01.nii
./vol_01.nii
在这种情况下最好使用以下语法./b01.nii* )
我已将您的替换mv
为echo
只是为了测试脚本:
for filename in $(find . -name "*"); do
case ${filename} in
./b01.nii* )
echo "$filename ${filename}/Users/dave/Desktop/test/untitled_folder_*/str" ;;
./vol_01.nii* )
echo "$filename ${filename}/Users/dave/Desktop/test/untitled_folder_*/rs" ;;
*)
echo "don't know where to put $filename";;
esac
done
我的输出是
sh-4.3$ bash -f main.sh
don't know where to put .
don't know where to put ./main.sh
don't know where to put ./.cg_conf
don't know where to put ./myfile_12345
don't know where to put ./myfile_17676
don't know where to put ./myfile_9898
don't know where to put ./Newfile.sh
./b01.nii ./b01.nii/Users/dave/Desktop/test/untitled_folder_*/str
./vol_01.nii ./vol_01.nii/Users/dave/Desktop/test/untitled_folder_*/rs
问候
克劳迪奥