title: Comparing variables with strings bash
body: <h2>Context</h2>
  
  <p>For quite a lot of our CentOS servers I would like to install some monitoring software, the software is based on the CentOS version, I want to check the release version and install software based on that.</p>
  
  <h2>Issue</h2>
  
  <p>It seems that the if statements are run successfully without errors while the results never should be true for both or all three if statements. I've looked into the if commands and the tests, it seems that I should use double brackets and single = symbol in bash. I believe that I'm doing something really simple wrong, but I just can't find it.</p>
  
  <h2>Code</h2>
  
  <pre><code>#!/bin/bash
  versionknown=false
  version=$(&lt;/etc/centos-release)
  known_version1="CentOS release 6.9 (Final)"
  known_version2="CentOS Linux release 7.3.1611 (Core)"
  
  if [[ "$version"="CentOS release 6.9 (Final)" ]] ; then
      echo "Same versions as expected"
      versionknown=true
      #run commands for this specific version
  fi
  
  if [[ "$version"="CentOS Linux release 7.3.1611 (Core)" ]] ; then
      echo "Same versions as expected v2"
      versionknown=true
      #run commands for this specific version
  fi
  
  
  if [[ "$versionknown"=false ]] ; then
      echo "Different version detected than known:"
      echo $version
      echo "Aborted"
  fi
  
  echo $versionknown
  </code></pre>
  
  <h2>Results</h2>
  
  <pre><code>Same versions as expected
  Same versions as expected v2
  Different version detected than known:
  CentOS Linux release 7.3.1611 (Core)
  Aborted
  true
  </code></pre>
  
  <h1>Update</h1>
  
  <p>After getting some responses I've changed my code, adding spaces around the equal signs(=). Still doesn't work as intended since the comparison should return true on the second if statement which it doesn't.</p>
  
  <h2>Code #2</h2>
  
  <pre><code>#!/bin/bash
  versionknown=false
  version=$(&lt;/etc/centos-release)
  known_version1="CentOS release 6.9 (Final)"
  known_version2="CentOS Linux release 7.3.1611 (Core)"
  
  if [[ "$version" = "CentOS release 6.9 (Final)" ]] ; then
          echo "Same versions as expected"
          versionknown=true
          #run script for this specific version
  fi
  
  if [[ "$version" = "CentOS Linux release 7.3.1611 (Core)" ]] ; then
          echo "Same versions as expected v2"
          versionknown=true
          #run script for this specific version
  fi
  
  
  if [[ "$versionknown" = false ]] ; then
          echo "Different version detected than known:"
          echo $version
          echo "Aborted"
  fi
  
  echo $versionknown
  </code></pre>
  
  <h2>Results #2</h2>
  
  <pre><code>Different version detected than known:
  CentOS Linux release 7.3.1611 (Core)
  Aborted
  false
  </code></pre>
  
  <h1>Update</h1>
  
  <p><code>declare -p version</code> learned me that <code>/etc/centos-release</code> has a space added to the end of the script file, I believe that on CentOS release 6.9 (Final) that wasn't the case. Adding the space in the string, or all together making use of my known_version variables and adding the space solves the issues, script now works as intended.</p>