title: If condition for "not equal" is not working as expected in shell script
body: <pre><code>#!/bin/bash
  a=2
  b=2
  COUNTER=0
  sam="abcd"
  sam1="xyz"
  sam2="mno"
  for x in ls | grep .rpm
  do
    `C=rpm -qpR $x | grep -v CompressedFileNames | grep -v PayloadFilesHavePrefix | wc -l`
  
    if [ "sam2"!="$sam1" ]
    then
      echo "${sam1}"
      echo "${sam2}"
      if [ $C -eq $a ]
      then
        COUNTER=$((COUNTER+1))
        echo "${x}"
        eval sam=$x
        #eval sam1=sam | cut -d '-' -f 1
        sam1=`echo "${sam}"| cut -d '-' -f 1`
  
        if [ $COUNTER -eq $b ]
        then
          break
        fi
      fi
    fi
    sam2=`echo "${x}"| cut -d '-' -f 1`
  done
  </code></pre>
  
  <p>This is the output I am getting:</p>
  
  <pre>
  xyz
  mno
  comps-4ES-0.20050107.x86_64.rpm
  comps
  comps
  comps-4ES-0.20050525.x86_64.rpm
  </pre>
  
  <p>My question is: why is the <code>if</code> condition returning true despite sam1 and sam2 being equal? I have checked for non-equality.</p>
  
  <p>Response is the same even if I use</p>
  
  <pre><code>if [ $C -eq $a ] &amp;&amp; [ "$sam2" != " $sam1" ]
  </code></pre>