Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 变量内部的批处理变量 我有一组变量,叫做p1到p9 我有两个变量来设置我感兴趣的范围 我想列出从最小范围+1到最大范围的所有变量_Batch File_Variables - Fatal编程技术网

Batch file 变量内部的批处理变量 我有一组变量,叫做p1到p9 我有两个变量来设置我感兴趣的范围 我想列出从最小范围+1到最大范围的所有变量

Batch file 变量内部的批处理变量 我有一组变量,叫做p1到p9 我有两个变量来设置我感兴趣的范围 我想列出从最小范围+1到最大范围的所有变量,batch-file,variables,Batch File,Variables,看起来是这样的(而且不会起作用) 我想看到的结果是: fff ggg hhh iii 您需要启用DelayedExpansion: @echo off Setlocal Enabledelayedexpansion set currentvar=5 set maxvar=9 set p1=aaa set p2=bbb set p3=ccc set p4=ddd set p5=eee set p6=fff set p7=ggg set p8=hhh set p9=iii set /a r

看起来是这样的(而且不会起作用)

我想看到的结果是:

fff

ggg 

hhh

iii

您需要
启用DelayedExpansion

@echo off
Setlocal Enabledelayedexpansion
set currentvar=5
set maxvar=9
set p1=aaa
set p2=bbb
set p3=ccc
set p4=ddd
set p5=eee
set p6=fff
set p7=ggg
set p8=hhh
set p9=iii
set /a result = %maxvar% - %currentvar%
echo Found %result% vars in the range.
:LOOP
if %currentvar% LSS %maxvar% (
set /a currentvar=%currentvar% + 1
echo !p%currentvar%! &REM This is how you make a comment in batch
goto LOOP
) else (
goto END
)
:END
Endlocal
这应该是你想做的。另外,要进行注释,请使用新行并键入
REM


蒙纳

这可能适合你:

@ECHO OFF &SETLOCAL
set /a currentvar=5
set /a maxvar=9
set /a RangeStart=currentvar+1
set p1=aaa
set p2=bbb
set p3=ccc
set p4=ddd
set p5=eee
set p6=fff
set p7=ggg
set p8=hhh
set p9=iii
set /a result=maxvar-currentvar
echo Found %result% vars in the range.
for /l %%a in (%RangeStart% 1 %maxvar%) do call echo(%%p%%a%%

非常感谢你。我很久没有批量发表任何评论了。我不知道你能用!扩展变量。这正是我所需要的。你太棒了。这不管用。在代码块内,您无法访问已更改的
%variables%
,例如
currentvar
!您将非工作答案标记为已接受。
@ECHO OFF &SETLOCAL
set /a currentvar=5
set /a maxvar=9
set /a RangeStart=currentvar+1
set p1=aaa
set p2=bbb
set p3=ccc
set p4=ddd
set p5=eee
set p6=fff
set p7=ggg
set p8=hhh
set p9=iii
set /a result=maxvar-currentvar
echo Found %result% vars in the range.
for /l %%a in (%RangeStart% 1 %maxvar%) do call echo(%%p%%a%%