function syncfile(){
echo "[ DONE $file ]"
return ;
}
function syncfolder(){
folder=$1
for foo in `ls -1 $folder`
do
file="$folder/$foo"
if [ -d $file ];then
syncfolder $file
elif [ -e $file ];then
syncfile $file
else
echo "$file is neither file nor directory"
fi
done
return;
}
以上是我的两个递归函数..当我调用 syncfolder $foldername
它时,在以下情况下没有给出正确的输出..
假设层次结构如下
portchanges/
portchanges/script/script1/script1.sh
portchanges/script/script1/script2.sh
portchanges/script/script1/script3.sh
portchanges/script/script4.sh
portchanges/script/script5.sh
portchanges/script6.sh
portchanges/script7.sh
portchanges/appl/script11/script11.sh
portchanges/appl/script11/script12.sh
portchanges/appl/script11/script13.sh
现在如果foldername=portchanges
我打电话syncfolder $foldername
它只处理
portchanges/script/script1/script1.sh
portchanges/script/script1/script2.sh
portchanges/script/script1/script3.sh
用function syncfile()
函数调用......然后它转到函数return
。syncfolder
它将搜索script6.sh
并script7.sh
在portchanges/script/script1/
目录中!这是完全不正当的行为!!
我应该怎么做它对整个文件夹进行递归处理,并且每个文件都可以syncfile()
正常工作?