title: increment a variable value inside a while loop in a shell script
body: <p>I'm trying to increment a variable value in a while loop, but I want to increment it twice. By "twice" I mean increment variable value first time, then do some operation and then increment already incremented value once more, and this is all inside a while loop. My code looks like this:</p>
  
  <pre><code>    i=1
      setglobal="SET GLOBAL "
      while [ $i -le $# ]
      do
           assign=$setglobal$i=$($i+1)
           START=`date +%s`
           mysql $database -u $user -se "$assign;select
           here goes my database query, not important"
           END=`date +%s`
           echo $END - $START | bc&gt;&gt;output.txt
           i=$(($i+1))
           mysqld restart
      done
  </code></pre>
  
  <p>And I have a list of arguments sent to my shell: innodb_change_buffer_max_size 16 key_buffer_size 1431655770, as 1st, 2nd, 3rd and 4th arguments respectively. So I want the while loop to do:</p>
  
  <pre><code>    SET GLOBAL innodb_change_buffer_max_size = 16
  </code></pre>
  
  <p>after </p>
  
  <pre><code>    assign=$setglobal$i=$($i+1)
  </code></pre>
  
  <p>and </p>
  
  <pre><code>    SET GLOBAL key_buffer_size = 1431655770
  </code></pre>
  
  <p>after </p>
  
  <pre><code>    i=$(($i+1))
      assign=$setglobal$i=$($i+1)
  </code></pre>
  
  <p>As a result, in my output.txt I should have got the running time of each query, however I get only four zeros. So I guess my loop is either not doing this part "SET GLOBAL key_buffer_size = 512" correctly, or it is not doing the right incrementation. Could anyone tell me what might be wrong with my code?       </p>