【发布时间】:2011-10-05 21:31:55
【问题描述】:
我正在尝试使用延迟变量扩展中的动态变量来表示其他动态变量。我遇到了一些麻烦。如果动态变量的值是另一个具有自己值的动态变量,如何获取动态变量的值?
即!valA! = %valB% = 这个
@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
...
...
FOR /F ... %%G IN (...) DO (
SET _temp=%%~nG
SET _file=!_temp:~0,-4!
SET _cnt=0
FOR /F ... %%L IN (...) DO (
SET _temp=%%L
SET _str=!_temp:*: =!
SET /A _cnt+=1
SET _temp=x!_file!!_cnt!
IF DEFINED !_temp! (
SET _temp=!%_temp%!
::
::_temp('s value) is _var('s value) is "xyz"
::Set new _temp to equal current _temp's "xyz"
::
IF !_temp! NEQ !_str! (
ECHO File Content Mismatch
)
) ELSE (
SET xvar=!_temp!
SET !xvar!=!_str!
)
)
)
...
...
exit
任何帮助将不胜感激。
【问题讨论】:
-
哇!博士级批处理脚本。我认为这些天每个人都明智并使用了 PowerShell
-
我很好奇这行:“SET _temp=!%_temp%!”。你能解释一下你想做什么吗?
-
@Arun 将 _temp 重新分配给当前的 _temp(变量名)值。
标签: variables dynamic batch-file return