title: Increment with bash
body: <p>I'm stuck trying to increment a variable in an .xml file. The tag may be in a file 100 times or just twice. I am trying to add a value that will increment the amount several times. I have included some sample code I am working on, but when I run the script it will only place a one and not increment further. Advice would be great on what I'm doing wrong.</p>
  
  <pre><code>for xmlfile in $(find $DIRECTORY -type f -name \*.xml); do
    TFILE="/tmp/$directoryname.$$"
    FROM='&gt;&lt;process&gt;'
    TO=' value\=""&gt;&lt;process&gt;'
    i=0
    while [ $i -lt 10 ]; do
      i=`expr $i + 1`
      FROM='value\=""'
      TO='value\="'$i'"'
    done
    sed "s/$FROM/$TO/g" "$xmlfile" &gt; $TFILE &amp;&amp; mv $TFILE "$xmlfile"
  done
  </code></pre>
  
  <p>The <code>while</code> loop was something I just placed to test the code. It will insert the <code>&lt;process&gt;</code> but it will not insert the increment.</p>
  
  <p>My end goal:</p>
  
  <pre><code>&lt;process&gt;value="1"&lt;/process&gt;
  &lt;process&gt;value="2"&lt;/process&gt;
  &lt;process&gt;value="3"&lt;/process&gt;
  &lt;process&gt;value="4"&lt;/process&gt;
  </code></pre>
  
  <p>And so on as long as <code>&lt;process&gt;</code> is present in the file it needs to increment.</p>