2017-04-25 49 views
2

我使用下面的shell代码将文件移动从一个位置到另一个位置:错误朝着外壳文件循环

for i in [ test1 test2 test3] 
do 
    mv /home/usr/enabler/$i/* /home/bin/enabler/consolidate 
    echo "moved successfully!!!" 
done                    

bash shell中运行出现错误"Illegal file pattern: Unclosed character class near index 1"。我希望循环到每个文件夹test1test2test3和移动存在的所有文件test1test2test3在目标文件夹。

+0

方括号似乎并没有在所有有用的在这里,你为什么把那些?同时要小心地引用你的变量。另请参见http://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-variable – tripleee

+1

一行:'MV /家庭的/ usr /推动者/ {TEST1,TEST2,TEST3}/* /家用/斌/推动者/ consolidate' –

回答

2

修正你的脚本方式:

for i in test1 test2 test3 
do 
    mv /home/usr/enabler/"$i"/* /home/bin/enabler/consolidate 
    echo "moved successfully!!!" 
done 

这正是你想!