Batch file 展望未来?变量
如何做到这一点Batch file 展望未来?变量,batch-file,variables,lookahead,Batch File,Variables,Lookahead,如何做到这一点 set newline=^& echo. set header=my header^%newline% %abc%^%newline%%def%^%newline%end 预期产出: my header some text some more text end my header hello there end 立即输出:(abc和def值不显示) 提前谢谢!感谢任何解决方案 更新: 我正在编写一个脚本,总结执行结果,并在输出的第一行显示它,例如 c:\>
set newline=^& echo.
set header=my header^%newline% %abc%^%newline%%def%^%newline%end
预期产出:
my header
some text
some more text
end
my header
hello
there
end
立即输出:(abc和def值不显示)
提前谢谢!感谢任何解决方案
更新:
我正在编写一个脚本,总结执行结果,并在输出的第一行显示它,例如
c:\> myScript.bat
----------------------------------------
Execution failed with cmd1=UP, cmd2=DOWN
cmd2 failed
----------------------------------------
COMMAND: cmd1
[output of cmd1]
cmd1 result is "UP"
COMMAND: cmd2
[outout of cmd2]
cmd2 result is "DOWN"
试试这个
或
据我所知,这是无法实现的。是您遇到了问题(可能由解决),还是能够动态更改替换到
标题中的内容?(提示:展示你所得到的/描述它是如何错误的,以及展示你想要的/期望的)。如果是后者,我怀疑您必须将set header=…
(可能还有一个echo%header%
)放在call:doheader
函数中,以便在abc
或def
更改时调用该函数。
my header
some text
some more text
end
my header
hello
there
end
my header
end
my header
end
c:\> myScript.bat
----------------------------------------
Execution failed with cmd1=UP, cmd2=DOWN
cmd2 failed
----------------------------------------
COMMAND: cmd1
[output of cmd1]
cmd1 result is "UP"
COMMAND: cmd2
[outout of cmd2]
cmd2 result is "DOWN"
@echo off
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
:::::
set header=my header%NL% %abc%%NL%%def%%NL%end
setlocal EnableDelayedExpansion
(set \n=^
%=Do not remove this line=%
)
set header=my header!\n! %abc%!\n!%def%!\n!end