Today I was playing with .bat code.
I would like to change title with changing variable in itself. The way I would like to use title command is from variable %t%
. I know where is the problem - The variable %t%
after set /a n=%n% + 1
is outdated and still have value n=0
. Is there any way to automatically update %t%
without typing again set t=title changing %n%
? I Thought there will be some way to "lock" the variable %n%
so it get the last possible value. (after typing itself in the %t%
)
set /a n=0
set t=title changing %n%
%t%
pause
set /a n=%n% + 1
%t%
pause
@echo off
setlocal EnableDelayedExpansion
set /a n=0
set "t=title changing ^!n^!"
%t%
pause
set /a n=%n% + 1
%t%
pause
For an explanation, look for "Delayed Expansion" in this site...
PS - You may enter set /a n=%n% + 1
in this way: set /a n=n + 1
or even in this simpler one: set /a n += 1