shell script: deleting files from a directory

i have the following problem:
use shell script:

Two directories have to be searched for files havin the same name.
then delete these files from one of these directories.
the directory names have to be accepted as command line arguments.

what i have done till now is:

  1. run a loop through both directories and
  2. tried to compare the filenames.
  3. i am not able to compare the names of files since the filenames are extracted alongwith the directory (dirname/filename)
  4. i tried using cut.

Suppose you want to compare two directories test1 and test2 and want to delete files from test2 directory if found in test1, you can do something like this:

#! /bin/ksh
for i in ./test1/*; do
filename=`basename $i`
if [[ -f ./test2/$filename ]]; then
rm ./test2/$filename
fi
done

Regards,
Tayyab