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:
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>>output.txt
i=$(($i+1))
mysqld restart
done
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:
SET GLOBAL innodb_change_buffer_max_size = 16
after
assign=$setglobal$i=$($i+1)
and
SET GLOBAL key_buffer_size = 1431655770
after
i=$(($i+1))
assign=$setglobal$i=$($i+1)
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?