| Script to compare directories I was trying to make write a shell script that would compare the number of files in 2 given directories.I 've come up with this : Code: #!/bin/bash
read -p "enter the first directory: " NAME1
read -p "enter the second directory: " NAME2
x=$(ls "$NAME1" |wc -l)
y=$(ls "$NAME2" |wc -l)
if [ "$x -gt $y" ] ; then
echo "first directory has more files"
elif [ "$x -eq $y" ] ; then
echo "direcories have the same number of files"
else
echo "second directory has more files"
fi
My problem here is that the result is always "first directory has more files" even if that's not true.Where is my mistake or what should I do..?Thanks in advance.. |