title: Simple bash scripting with echo, sed, and variables
body: <p>I'm having this problem:
  I want to use the sed command to replace a line in a file,</p>
  <pre><code>sudo sed -i 's/option=setting A/option=setting B/g' ~configfile
  </code></pre>
  <p>This line should be part of a .sh file, so I added &quot;&gt; myscript.sh&quot; (which is represented by variables below). I also have several possible options variables that are listed in a list:</p>
  <blockquote>
  <p>options.list</p>
  </blockquote>
  <p>Which contains</p>
  <blockquote>
  <p>A</p>
  <p>B</p>
  <p>C</p>
  </blockquote>
  <p>So, I want to search and replace a variable, no matter what it was, to the new value within the list. That's why I used <code>option=.*$</code> in the first part of sed. The second part of the sed should combine the chain <code>&quot;setting= &quot;</code> with all the options from options.list. All that have to be pushed in a .sh file.</p>
  <p>So, to combine the whole stuff I tried this:</p>
  <pre><code>while IFS= read -r file
  do
       echo &quot;#!/bin/bash&quot; &gt;&gt; &quot;$_dest&quot;&quot;$file&quot;.sh
       echo sed -i 's/option=.*$/option=&quot;setting &quot;&quot;$file&quot;/g' ~configfile &gt;&gt; &quot;$_dest&quot;&quot;$file&quot;.sh        
  done &lt; &quot;$options.list&quot;
  </code></pre>
  <p>But there is a problem with echo and sed, probably related with backslashes or something... I tried hard but still with no solution. SOrry I know this is probably a silly question :)</p>