title: Update var in ini file using bash
body: <p>I am attempting to write a bash script to configure various aspects of a server. The context here is replacing a value of a variable in a conf file (ini format) with another value.</p>
  
  <p>The context is</p>
  
  <pre><code>[ssh-iptables]
  
  enabled = false
  </code></pre>
  
  <p>And I simply need to change false to true.</p>
  
  <p>Typically I'd just do this with a simple bit of <code>sed</code></p>
  
  <pre><code>sed -i 's/^enabled = false/enabled = true/g' /etc/fail2ban/jail.conf
  </code></pre>
  
  <p>But <code>enabled = false</code> exists in multiple places.</p>
  
  <p>I've tried using <code>awk</code> with no success</p>
  
  <pre><code>awk -F ":| " -v v1="true" -v opt="enabled" '$1 == "[ssh-iptables]" &amp;&amp; !f {f=1}f &amp;&amp; $1 == opt{sub("=.*","= "v1);f=0}1' /etc/fail2ban/jail.conf
  </code></pre>
  
  <p>The above was sourced from <a href="http://www.unix.com/302321572-post5.html">this forum thread</a> but I don't really have enough understanding of how to use it in scripts to make it work. All it seems to do is the equivalent of <code>cat /etc/fail2ban/jail.conf</code></p>
  
  <p>I have found a few other scripts which are considerably longer which isn't ideal as this will happen to loads of ini files so I'm hoping someone can help me correct the above code or point me in the right direction.</p>
  
  <p>Apologies if this belongs on ServerFault, but as it's scripting rather than the intricacies of server configuration itself I figured here might be more apt.</p>