[SlugBug] shell script help

Bill Best bill at commedia.org.uk
Thu Aug 7 15:03:52 BST 2003


Chris J wrote:

>cmp prints out stuff when it finds a difference, so the $(cmp ... ) gets
>expanded to:
>
>        file1 file2 differ: char XX, line XX
>
>so you need to invoke cmp with "-s", which says "run silently".
>
>Btw, I couldn't get it to work; first it didn't like the "-eq 0" and then,
>if taking that out, it always returned false.
>
>So, if you have problems, try splitting the "if [ $(cmp ... ]; then" line
>as follows:
>
>        cmp -s $FILE1 $FILE2
>        if [ $? -eq 0 ]; then
>            .
>            .
>            .
>
>Which seems to work okay. Or to cut the "if...fi" block to a single line:
>
>        [ $? -eq 0 ] && echo $FILE1 $FILE2
>
>Chris...
>
many thanks for everyone's help with this.  the definitive script (apart 
from daniel's that i've just seen) is thus which works a treat:

for FILE in $(ls directory1/*); do
 for FILE2 in $(ls directory2/*); do
   cmp -s $FILE $FILE2
    [ $? -eq 0 ] && echo $FILE $FILE2
    done
done

sorry for the lame-ness, but i would know like to produce a report of 
these file duplications and then have that emailed to me.

for FILE in $(ls directory1/*); do
 for FILE2 in $(ls directory2/*); do
   cmp -s $FILE $FILE2
    [ $? -eq 0 ] && echo $FILE $FILE2 >> same.txt
    done
done

how do i get same.txt to be emailed to me?

bill
-- 
don't anthropomorphize computers - they don't like it.



More information about the SlugBug mailing list