Linux bash shell脚本中Md5 sum的结果不正确

Linux bash shell脚本中Md5 sum的结果不正确,linux,bash,shell,md5,Linux,Bash,Shell,Md5,我丢失了一些本应在脚本运行时存档的图像。我想这可能与我的缩进或Md5金额有关。我已经尝试了我能想到的一切 以下是没有正确缩进的代码: #!/bin/sh if [ ! -d "$1" ]; then echo Directory "$1" cannot be found. Please try again. exit fi if [ $# -eq 1 ]; then echo "usage: Phar image_path archive_path" exi

我丢失了一些本应在脚本运行时存档的图像。我想这可能与我的缩进或Md5金额有关。我已经尝试了我能想到的一切

以下是没有正确缩进的代码:

#!/bin/sh

if [ ! -d "$1" ]; then
    echo Directory "$1" cannot be found. Please try again.
    exit
fi

if [ $# -eq 1  ]; then
    echo "usage: Phar image_path archive_path"
    exit
fi

if [ -d "$2" ]; then
    echo "archive exists"
else
    echo "the directory 'archive' does't exist. Creating directory 'archive'."
    mkdir -p ~/archive 
fi

find $1 -iname "IMG_[0-9][0-9][0-9][0-9].JPG" | cat > list.txt

[ -f ~/my-documents/md5.txt ] && rm md5.txt || break 
while read line;
    do md5sum $line | xargs >> md5.txt 
done < list.txt 

sort -k 1,1 -u md5.txt | cat > uniquemd5.txt 
cut -d " " -f 2- uniquemd5.txt > uniquelist.txt 

sort uniquelist.txt -r -o uniquelist.txt
for line in $(cat uniquelist.txt)
do
    file=$(basename $line) path="$2/file"

    if [ ! -f $path ];
    then 
        cp $line $2 
    else 
        cp $line $path.JPG 
    fi 

    rm uniquelist.txt md5.txt uniquemd5.txt list.txt

done
#/垃圾箱/垃圾箱
如果[!-d“$1”];然后
找不到回显目录“$1”。请再试一次。
出口
fi
如果[$#-eq 1];然后
echo“用法:Phar图像\u路径存档\u路径”
出口
fi
若[-d“$2”];然后
echo“存档存在”
其他的
echo“目录'archive'不存在。正在创建目录'archive'
mkdir-p~/archive
fi
查找$1-iname“IMG|[0-9][0-9][0-9][0-9].JPG“| cat>list.txt”
[-f~/my documents/md5.txt]&rm md5.txt | | break
读行时;
md5sum$line | xargs>>md5.txt
完成uniquemd5.txt
剪切-d”“-f 2-uniquemd5.txt>uniquelist.txt
排序uniquelist.txt-r-o uniquelist.txt
对于$中的行(cat uniquelist.txt)
做
文件=$(basename$行)路径=“$2/文件”
如果[!-f$path];
然后
cp$行$2
其他的
cp$line$path.JPG
fi
rm uniquelist.txt md5.txt uniquemd5.txt list.txt
完成
此循环

while read line;
    do md5sum $line | xargs >> md5.txt 
done < list.txt
读行时
;
md5sum$line | xargs>>md5.txt
完成
应该是

while read line;
    do md5sum "$line" 
done < list.txt > md5.txt
读行时
;
不计算md5sum“$line”
完成md5.txt

引用参数扩展,不清楚为什么需要。

请发布实际代码,而不是图片!你能解释一下你想用剧本做什么吗?这里有几条相当混乱的线。为什么
find$1-iname“IMG”[0-9][0-9][0-9][0-9].JPG“| cat>list.txt
而不是
find$1-iname“IMG”[0-9][0-9][0-9].JPG>list.txt
xargs
md5sum$line | xargs>>md5.txt
上做什么?