File comparison in shell script

Hi,

I have written one script :

#!/bin/bash

echo -n -e "\nEnter how many files : "
read no

for (( j=1; j<=$no; j++ ))
do
    echo -n -e "\nEnter $j File name : "
    read name[$j]
done

for (( j=1; j<=$no; j++ ))
do
    FILE=`find ./ -type f -name "${name[$j]}"`
    echo "$FILE"
done

Output:

Enter how many files : 2

Enter 1 File name : word.sh

Enter 2 File name : dfile.sh

./word/word.sh
./word.sh
./dfile.sh

I need script that should print "word.sh file present in multiple path"
so how do i compare "word.sh" ????

you can extract the filename by command---basename

1 Like

You can something like:

FILE=`find ./ -type f -name "${name[$j]}"`
if [ `echo "$FILE"|wc -l` -gt 1 ]
then
  echo "$FILE present in multiple path"
fi
1 Like

Thank you very much!!!