title: Comparing two strings in linux KSH script
body: <p>I have two files: file1 and file2. Here is a sample of the files content:</p>
  
  <pre><code>&lt;TG&gt;
     &lt;entry name="KEYNAME" val="" type="string" /&gt;
     &lt;entry name="KEYTYPE" val="" type="string" /&gt;
     &lt;entry name="TIMEZONE_OFFSET" val="-240" type="INT16" /&gt;
     ...
  &lt;/TG&gt;
  </code></pre>
  
  <p>I want to check if certain lines (those containing the string "entry name") in file1 exist in file2, and then if yes, compare if the two lines are identical or not.</p>
  
  <p>I literally created file2 by copying file1, then I changed a few values. The problem is that comparing the two string variables does not return correct values. Although when displaying the two variables I can see they are identical, the result of the comparison gives that they are not. I am using Ksh. Here is my code:</p>
  
  <pre><code>while read p; do
      if [[ $p == *"entry name"* ]]; then
          PARAM_NAME=$(echo $p | cut -d '"' -f2)
          echo $PARAM_NAME
          PARAM_OLD=$(grep $PARAM_NAME file2)
          if [[ $PARAM_OLD == *"entry name"* ]]; then
              echo $PARAM_OLD
              echo $p
              if [ "$PARAM_OLD" = "$p" ]; then
                  echo 'Identical values'
              else
                  echo 'Different values'
              fi
          else
              echo "$PARAM_NAME does not exist in previous version file. Using default value"         
          fi
      fi
  done &lt;file1
  </code></pre>
  
  <p>I tried all possibilities for the parenthesis, equal signs and quotations ([], [[]], = , ==, "", '""', etc.)</p>
  
  <p>Here is the output I am getting:</p>
  
  <pre><code>&lt;entry name="KEYNAME" val="" type="string" /&gt;
  KEYNAME
  &lt;entry name="KEYNAME" val="" type="string" /&gt;
  &lt;entry name="KEYNAME" val="" type="string" /&gt;
  Different values
  &lt;entry name="KEYTYPE" val="" type="string" /&gt;
  KEYTYPE
  &lt;entry name="KEYTYPE" val="" type="string" /&gt;
  &lt;entry name="KEYTYPE" val="" type="string" /&gt;
  Different values
  &lt;entry name="TIMEZONE_OFFSET" val="-24" type="INT16" /&gt;
  TIMEZONE_OFFSET
  &lt;entry name="TIMEZONE_OFFSET" val="-240" type="INT16" /&gt;
  &lt;entry name="TIMEZONE_OFFSET" val="-24" type="INT16" /&gt;
  Different values
  </code></pre>
  
  <p>Still I am getting that the strings are different! I would appreciate any explanation and help. </p>