#!/bin/sh # Program name: comp_dirs_file_match # # I had two directories with a ton of files in each: # # ~/cpprogs # ~/ap/e/cpprogs # # I didn't want to just copy the contents of one into the # other and overwrite a better version with a crappy one # so I thought it was a good excuse to write a sh script <;) # echo -e "\ #####################################################################\n\ Comparing Directories for matching files: \n"; echo -e "\n########## getting clargs ##########\n"; echo -e " $# parameters given: \n $@\n"; echo -e "That's: $1 \n and: $2"; echo; if [ $# -lt 2 ]; then echo "dude , please 2 directoy names on the command line"; exit; fi; echo -e "\n########## test for "name is directory?" ##########\n"; ((t1=0)); # enclose in (( )) for math operations. if [ -d $1 ]; then echo "$1 - YES"; else echo "$1 - NO"; ((t1+=1)); fi; if [ -d $2 ]; then echo "$2 - YES"; else echo "$2 - NO"; ((t1+=1)); fi; echo $t1; echo echo -e "########## string comparison test ##########\n"; a="hello"; b="hello"; if [ "$a" == "$b" ] ; then echo "$a matches $b"; else echo "$a does NOT match $b"; fi; echo; echo -e "\ ##################################################################### \n\ # Ok so loop on ls of first directory given and take each filename \n\ # to a loop on ls of the second directory and compare the words for \n\ # match: \n\ ##########\n"; t1=0; ((t2=0)); for fn1 in $(ls $1); do # echo $fn2; ((t1++)); for fn2 in $(ls $2); do if [ "$fn1" == "$fn2" ]; then echo "Match found: $fn1"; ((t2++)); fi; done; done; echo -e " Total: $t1 file names checked in $1 \n $t2 matches found"; echo -e "\n########## WOW - how simple! ##########\n";