linux - variable plus 1 after each time running the script -


for file in `ls |grep '\..$'` num=0 while [ $num -lt 100 ] num=`expr $num + 1` sed -i "_bak" "s/\/\/.*version.*/\/\/calcmarks, version $num ,released `date "+%a %b %d %h:%m:%s %z %y"`/" "$file" done 

what want let variable each time run script , variable plus 1. example, original textile is

//calcmarks, version 1 ,released thu apr 06 20:50:54 awst 2017

after run script ,i hope become

//calcmarks, version 2 ,released xxxxxxxxxxxxx

and then

//calcmarks, version 3 ,released xxxxxxxxxxxxxx

so set variable $num

i don't quite see, how question related code posting (where increment variable within loop), when want store state (here: version number) between script invocations, need store value in file.

create file $home/version, , store version number in file. on each invocation, read content of file, increment variable, , write file.

while trivial, there 1 tricky aspect contained: if run 2 instances of script in parallel, have race condition updating version number. on safe side, should consider file locking.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -