0

我尝试将文件从一个目录移动到另一个目录,但没有成功。所以我搜索并找到了一个适合我想要的答案。当我运行它,修改到我的目录时,它给出了

想要做什么:

${filename,,*}: 糟糕的替代品!

这是我使用的:

for filename in *; do
  case "${filename,,*}" in
    b01.nii*)    mv "$filename" "$/Users/dave/Desktop/test/untitled_folder_*/str" ;;
    vol_01.nii*) mv "$filename" "$/Users/dave/Desktop/test/untitled_folder_*/rs" ;;
    *)           echo "don't know where to put $filename";;
  esac
done

谢谢

4

1 回答 1

0

你有两个错误:

主要问题是 for 命令,变量$filename包含*而不是真实文件名。你应该使用文件名$(find . -name "*");do

第二个是这样的:

您必须确定变量的$filename值,即在我的 bash shell 中,文件名输出是

./b01.nii 
./vol_01.nii 

在这种情况下最好使用以下语法./b01.nii* )

我已将您的替换mvecho只是为了测试脚本:

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 

问候

克劳迪奥

于 2016-02-24T12:12:40.757 回答