[SlugBug] shell script help

Bill Best bill at commedia.org.uk
Thu Aug 7 12:52:32 BST 2003


Hi

Beneath wrote:

>>i want to write a bash script to compare each file in directory2 to
>>each file in directory1 and, if the files are the same, to delete the
>>file in directory2.  if a file in directory2 does not match any file
>>in directory1 then no action is taken.
>>    
>>
>
>for FILE in $(ls directory1/*); do
>  for FILE2 in $(ls directory2/*); do
>    if [ $(cmp $FILE $FILE2) -eq 0 ]; then
>      rm $FILE2
>    fi
>  done
>done
>
Many thanks for this, Daniel.  Before running this script, I amended it 
just to check it, so it now looks like:

for FILE in $(ls directory1/*); do
  for FILE2 in $(ls directory2/*); do
    if [ $(cmp $FILE $FILE2) -eq 0 ]; then            #problem here
       echo $FILE $FILE2
    fi
  done
done

but it bombs out with:
                                         [: too many arguments
for the line indicated above.

Anyone got any ideas?

Cheers

bb



More information about the SlugBug mailing list