title: Bash: increment a variable from a script every time when I run that script
body: <p>I want that a variable from a script to be incremented every time when I run that script. Something like this:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>#!/bin/bash    
  n=0   #the variable that I want to be incremented
  next_n=$[$n+1]
  sed -i "2s/.*/n=$next_n/" ${0}
  echo $n
  </code></pre>
  
  <p>will do the job, but is not so good if I will add other lines to the script before the line in which the variable is set  and I forget to update the line <code>sed -i "2s/.*/n=$next_n/" ${0}</code>.</p>
  
  <p>Also I prefer to not use another file in which to keep the variable value.</p>
  
  <p>Some other idea?</p>