Im trying to write a bash script in unix that loops through two different directories and compares every file in $1 and every file in $2. If the file has the same name and different content as a file in $1 as it does in $2, I want it to print “fileFrom$1 : fileFrom$2 exists but contents differ”. If the file has the same name AND same content I want it to print “fileFrom$1 : filefrom$2 matches – removing from $2” (Note: This does not actually remove the file it only prints that statement). If there is a file in $1 that does not exist in $2 I want it to print “fileFrom$1 : no fileFrom$1 in $2.

Here is a sample output:

../nodups A B A/al.txt : B/al.txt matches – removing from B A/bl.txt : B/bl.txt exists but contents differ A/cl.t” src=”https://files.transtutors.com/cdn/qimg/baa8dee68313447c81a1a45d2b771735.jpg” aria-describedby=”c00″>

Here is a my current loop to iterate through both directories and compare each file however it doesn't work as intended:

This does not print what I want, it instead only prints “A : no B in B” when run like this ./nodups A B

The output should instead match the output pictured above. Can someone please help me fix my program? elvis:- 27> ../nodups A B A/al.txt : B/al.txt matches – removing from B A/bl.txt : B/bl.txt exists but contents differ A/cl.txt : no cl.txt in B # Loop on all files in $1 # 1) if there is a file with same name in $2, # use “cmp-” to see whether contents are the same # print result (either contents match or contents differ) # 2) if there is no file with same name in $2, print message for filename in $1; do for file in $2; do if [ $filename == $file ]; then if [ $ (cmp -s $filename $file) == 1 ]; then echo $filename : $file exists but contents differ else echo $filename : $file matches – removing from $2 fi else echo $filename : no $file in $2 fi done done

"Get 15% discount on your first 3 orders with us"
Use the following coupon
"FIRST15"

Order Now