1

I'm extracting two md5sums by using this code:

md5sum test{1,2} | cut -d' ' -f1-2 

I'm receiving two md5sums as in example below:

02eace9cb4b99519b49d50b3e44ecebc 
d8e8fca2dc0f896fd7cb4cb0031ba249 

Afterwards I'm not sure how to compare them. I have tried using the xargs:

md5sum test{1,2} | cut -d' ' -f1-2 | xargs bash -c '$0 == $1'

However, it tries to execute md5sum as a command

Any advice?

c0d33p
  • 11
  • 1

1 Answers1

0

Try using a command subsitution instead

#!/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
fi
philn
  • 474
  • 4
  • 13
  • I just added the echo statement after &&: `md5sum test{1,3} | cut -d' ' -f1-2 | xargs bash -c 'diff -u – c0d33p Jun 25 '21 at 18:06