Because "&&" is a shell construct and you're giving it to test as an argument.find . -name '*.java' -type f -exec echo test -e ../"$2"/{} '&&' diff {} ../"$2"/{} ';' find . -name '*.java' -type f -exec test -e ../"$2"/{} '&&' diff {} ../"$2"/{} ';'
Sitting where the one and two directories are immediately below, dircomp one two produces the following:
test -e ../two/./x.java && diff ./x.java ../two/./x.java test -e ../two/./y.java && diff ./y.java ../two/./y.java test -e ../two/./z.java && diff ./z.java ../two/./z.java test: too many arguments test: too many arguments test: too many arguments
The echo'd statements look OK to me, so why the test errors?
I would be inclined to do something along these lines:
(cd one; find -type f -name *.java) | while read file; do cmp -s "one/$file" "two/$file" && echo rm "two/$file" done 2>/dev/null
cmp exits non-zero when the files differ or when one of them doesn't exist. Remove the "echo" when you're sure it's working or, as I usually do, put "| sh -x" after the "2>/dev/null". That redirect is there to throw away error messages from cmp complaining about differing files.
jch
-- Shrike-list mailing list Shrike-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/shrike-list