如何从批处理文件输出中插入换行符?
我想做的事情是:
echo hello\nworld
这将输出:
hello
world
如何从批处理文件输出中插入换行符?
我想做的事情是:
echo hello\nworld
这将输出:
hello
world
当前回答
为什么不使用子字符串/替换空格来echo;?
set "_line=hello world"
echo\%_line: =&echo;%
结果:
hello
world
或者,将\n替换为echo;
set "_line=hello\nworld"
echo\%_line:\n=&echo;%
其他回答
这对我来说很有效,不需要延迟扩展:
@echo off
(
echo ^<html^>
echo ^<body^>
echo Hello
echo ^</body^>
echo ^</html^>
)
pause
它像这样写输出:
<html>
<body>
Hello
</body>
</html>
Press any key to continue . . .
Echo hello & Echo .world
这意味着您可以定义& echo。作为换行符的常数\n。
Use:
echo hello
echo:
echo world
在这里,创建一个.bat文件,其中包含以下内容:
@echo off
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
REM Example Usage:
echo There should be a newline%NL%inserted here.
echo.
pause
您应该会看到如下输出:
There should be a newline
inserted here.
Press any key to continue . . .
显然,您只需要REM语句之间的代码。
要批量地开始新一行,你所要做的就是添加“echo[”,像这样:
echo Hi!
echo[
echo Hello!