title: Escaping dollar sign when echo write to file in CentOS linux bash script
body: <p>I am working on a bash script that needs to create a file in this location:</p>
  
  <p><strong>/etc/yum.repos.d/nginx.repo</strong></p>
  
  <p>with the following contents:</p>
  
  <pre><code>[nginx]
  name=nginx repo
  baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  gpgcheck=0
  enabled=1
  </code></pre>
  
  <p>So, I have tried to do it like this:</p>
  
  <pre><code>cat &gt;/etc/yum.repos.d/nginx.repo &lt;&lt;EOL
  [nginx]
  name=nginx repo
  baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
  gpgcheck=0
  enabled=1
  EOL
  </code></pre>
  
  <p>When I check the contents of the file, I see the following:</p>
  
  <p><a href="https://i.stack.imgur.com/MPA6U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MPA6U.png" alt="enter image description here"></a></p>
  
  <p>As you can see, the dollar sign weren't getting escaped, so the variable was evaluated to null/empty string and the contents do not look correct. Because, when I try to install nginx, I get this error:</p>
  
  <blockquote>
    <p><a href="http://nginx.org/packages/centos///repodata/repomd.xml" rel="nofollow noreferrer">http://nginx.org/packages/centos///repodata/repomd.xml</a>: [Errno 14] HTTP Error 404 - Not Found</p>
  </blockquote>
  
  <p>Any ideas?</p>