文件md5码比较脚本

代码文件命名 file_diff.sh,使用时执行 bash file_diff.sh file_1 file_2

#!/bin/bash 

set -e
set -o pipefail
set -u

if [[ ${UID} -eq 0 ]]; then
    echo "do not run this script as root"
    exit 1
fi

FILE_1=$1
FILE_2=$2

md5_1=`md5sum $FILE_1`
array=(`echo $md5_1 | tr ' ' ' '` )
md5_1=${array[0]}

md5_2=`md5sum $FILE_2`
array=(`echo $md5_2 | tr ' ' ' '` )
md5_2=${array[0]}

echo "md5 of file $FILE_1: $md5_1"
echo "md5 of file $FILE_2: $md5_2"

if [ "$md5_1" != "$md5_2" ];then
    echo "not equal"
else
    echo "equal"
fi

你可能感兴趣的:(文件md5码比较脚本)