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
  • Please add your desired output. – Cyrus Jun 25 '21 at 17:48
  • I have used this code: `md5sum test{1,2} | cut -d' ' -f1-2 | xargs bash -c 'diff -u <(echo "$0") <(echo "$1")'` However it only provide output when files differ... – c0d33p Jun 25 '21 at 17:49
  • You know about the `diff` command right? – philn Jun 25 '21 at 17:51
  • @Cyrus I would like to get info that the two strings are exactly the same. Something like "Equal". Please note I'm trying to make it as one liner without using sed and awk. – c0d33p Jun 25 '21 at 17:51

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
  • 654
  • 6
  • 17
  • I just added the echo statement after &&: `md5sum test{1,3} | cut -d' ' -f1-2 | xargs bash -c 'diff -u <(echo "$0") <(echo "$1") && echo Success'` However it's not so clean... Additionally i would like to compare without creating new files. – c0d33p Jun 25 '21 at 18:06