我使用下面的代码提取两个md5sums:
md5sum test{1,2} | cut -d' ' -f1-2 我收到两个md5sums,如下例所示:
02eace9cb4b99519b49d50b3e44ecebc
d8e8fca2dc0f896fd7cb4cb0031ba249 之后,我不确定如何比较它们。我尝试过使用xargs:
md5sum test{1,2} | cut -d' ' -f1-2 | xargs bash -c '$0 == $1'但是,它会尝试将md5sum作为命令执行
有什么建议吗?
发布于 2021-06-26 01:50:02
请尝试使用command subsitution
#!/bin/bash
echo 1 > file_a
echo 2 > file_b
echo 1 > file_c
file1=file_a
# try doing "file2=file_b" as well
file2=file_c
if [[ $(sha1sum $file1 | cut -d ' ' -f1-2) = $(sha1sum $file2 | cut -d ' ' -f1-2) ]]; then
echo same
else
echo different
fihttps://stackoverflow.com/questions/68135079
复制相似问题