批量展望未来?变量

时间:2017-10-17 07:55:39

标签: batch-file variables lookahead

如何实现这一目标?

set newline=^& echo. 
set header=my header^%newline% %abc%^%newline%%def%^%newline%end

...

set abc=some text 
set def=some more text 
echo %header%

...

set abc=hello
set def=there
echo %header%

预期产出:

my header
some text
some more text
end
my header
hello
there
end

立即输出:(不显示abc和def值)

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"

1 个答案:

答案 0 :(得分:1)

@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