简体   繁体   中英

Batch - Using variable inside a variable

Hello , 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 /an=%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

sorry for not good EN, THX for any response <3

@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 /an=%n% + 1 in this way: set /an=n + 1 or even in this simpler one: set /an += 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM