Right now, this is what my code looks like:
#!/bin/bash
Dir1=$1
Dir2=$2
for file1 in $Dir1/*; do
for file2 in $Dir2/*; do
if [[ $file1 == $file2 ]]
It doesn't work because you're comparing variables that contain the directory prefix. Just remove the prefix before comparing:
name1=${file1##*/}
name2=${file2##*/}
if [[ $name1 == $name2 ]]; then
echo "$name1 exists in both directories"
fi
Also, nested loops seems like an inefficient way to do this. You just need to get the filenames from one directory, and use a simple file existence check for the other directory.
for file in $Dir1/*; do
name=${file##*/}
if [[ -f $Dir2/$name ]]; then
echo "$name exists in both directories"
fi
done