From 9a592130b2d7d4126100b328adfd836b94019e17 Mon Sep 17 00:00:00 2001 From: vanquisher <32311274+Prajwalmithun@users.noreply.github.com> Date: Wed, 1 Jun 2022 17:32:40 +0530 Subject: [PATCH] added solution for directories_comparision.md (#249) * added solution to directories_comparision.md * updated the previous shell code --- .../shell/solutions/directories_comparison.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 exercises/shell/solutions/directories_comparison.md diff --git a/exercises/shell/solutions/directories_comparison.md b/exercises/shell/solutions/directories_comparison.md new file mode 100644 index 0000000..083ed74 --- /dev/null +++ b/exercises/shell/solutions/directories_comparison.md @@ -0,0 +1,30 @@ +## Directories Comparison + +### Objectives + +1. You are given two directories as arguments and the output should be any difference between the two directories + +### Solution + +Suppose the name of the bash script is ```dirdiff.sh``` + +``` +#!/bin/bash + +if test $# -ne 2 +then + echo -e "USAGE: ./dirdiff.sh directory1 directory2" + exit 1 +fi + +# check for the checksums. +# If both the checksums same, then both directories are same +if test `ls -1 $1 | sort | md5sum | awk -F " " '{print $1}'` == `ls -1 $2 | sort | md5sum | awk -F " " '{print $1}'` +then + echo -e "No difference between the 2 directories" + exit 0 +fi + +diff -q $1 $2 + +``` \ No newline at end of file