compare是自定义的比较工具,可以更换成Linux操作系统自带的diff工具
Shell脚本如下
#!/bin/bash
function getdir()
{
for element1 in `find $1`
do
for element2 in `find $2`
do
#首先判断对象是目录还是文件
if [ -d $element1 ]||[ -d $element2 ];
then
#是目录
echo "Is a Directory!"
else
#是文件
echo $element1
echo $element2
./compare $element1 $element2
RESULT=$?
if [ "$RESULT" == 3 ];
then
echo "file is different"
elif [ "$RESULT" == 2 ];
then
echo "file is same"
elif [ "$RESULT" == 255 ];
then
echo "has something wrong"
fi
fi
done
done
}
root_dir="/home/zzl/compareFile-main/hello"
comm_dir="/home/zzl/compareFile-main/bye"
getdir $root_dir $comm_dir #函数传参