简体   繁体   English

批处理 - 在变量中使用变量

[英]Batch - Using variable inside a variable

Hello , today I was playing with .bat code .你好,今天我在玩.bat 代码 I would like to change title with changing variable in itself.我想通过改变变量本身来改变标题。 The way I would like to use title command is from variable %t% .我想使用 title 命令的方式来自变量%t% I know where is the problem - The variable %t% after set /an=%n% + 1 is outdated and still have value n=0 .我知道问题出在哪里- set /an=%n% + 1后的变量%t%已过时,并且仍然具有值n=0 Is there any way to automatically update %t% without typing again set t=title changing %n% ?有没有办法自动更新%t%而无需再次输入set t=title changing %n% I Thought there will be some way to "lock" the variable %n% so it get the last possible value.我认为会有一些方法来“锁定”变量%n%以便它获得最后一个可能的值。 (after typing itself in the %t% ) (在%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抱歉,EN 不好, THX 任何回复 <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 PS - 你可以用这种方式输入set /an=%n% + 1set /an=n + 1 ,甚至更简单的: set /an += 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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