I'm attempting to compare the name of a directory to a line in a text file. However even when the name of the directory and the line in the text file are the same I can't seem to get them to be "equal".
#!/bin/bash
for dir in /mnt/hgfs/VM/Command_for_Dozing_Logs/*/
do
dir=${dir%*/}
dir=${dir:(-10)}
echo "Dir:$dir:"
while read p; do
echo "File:$p:"
if [ "$dir" == "$p" ]
then
echo "Variables are equal!"
fi
done </mnt/hgfs/VM/copiedFolders.txt
done
The folders I'm trying to match are in the Command_for_Dozing_Logs folder. The folders in it are:
2015.07.07
2015.07.08
My text file is like so:
2015.07.08
2015.05.23
So there should be at least one match, right? But no. I'm getting this as my output:
Dir:2015.07.07:
:ile:2015.07.08
:ile:2015.05.23
Dir:2015.07.08:
:ile:2015.07.08
:ile:2015.05.23
I'm really confused as to what's going on here. Why would that colon be replacing the first letter? How can I get the two variables to match?
tr -d '\015' < .../copiedFolders.txt > /tmp/fixed_copiedFolders.txt
and then run it with/tmp/fixed_copiedFolders.txt
instead. – Chris Davies Jul 14 '15 at 13:25