Compare two strings, UNIX Shell Programming

I've tried to compare two strings in an if statement using unix shell in FreeBSD (/bin/sh) and is not working. I think the problem appear for lenghty strings.

What could be wrong with that:

Code:
if [ "$testFileLine" = "ASCII C++ program text, with CRLF line terminators" ] ; then
    echo $testFileLine
fi

In this example the script never enter the if statement even testFileLine var have the same value as right string.
 
I don't think I have line breaks.

There is the whole script:

Code:
#!/bin/sh

find ./ >files_list.txt
fileList="files_list.txt"
fileLine=" "

while [ 1 ]
do
read fileLine || break
testFileLine=`file $fileLine | cut -d":" -f2| tr -d "\n"`
if [ "$testFileLine" = "ASCII C++ program text, with CRLF line terminators" ] ; then
    echo "this is a C++ source code"
    echo $testFileLine
fi
done < $fileList

I've tried first witout piping to tr command. Also I've tried using tr with \r instead of \r.
 
How about this instead?

Code:
#!/bin/sh

for f in $( find . -type f ); do
  if file ${f} |grep -q "ASCII C++ program text, with CRLF line terminators"; then
    echo "this is a C++ source code"
    echo ${f}
  fi
done
 
There's an even simpler way if you don't mind the original output of file(1).

Code:
#!/bin/sh

find . -type f -exec file {} \; |grep "ASCII C++ program text, with CRLF line terminators"

:)
 
Back
Top