如何从批处理文件输出中插入换行符?
我想做的事情是:
echo hello\nworld
这将输出:
hello
world
如何从批处理文件输出中插入换行符?
我想做的事情是:
echo hello\nworld
这将输出:
hello
world
当前回答
你也可以这样做,
(for %i in (a b "c d") do @echo %~i)
输出将是,
a
b
c d
请注意,当将其放入批处理文件中时,'%'应该加倍。
(for %%i in (a b "c d") do @echo %%~i)
其他回答
要回显换行符,请添加一个点。就在回声之后:
echo.
在这里,创建一个.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 hello & Echo .world
这意味着您可以定义& echo。作为换行符的常数\n。
当回显某些内容以重定向到文件时,多个回显命令将不起作用。我认为“>>”重定向器是一个不错的选择:
echo hello > temp echo world >> temp
简单的
set nl=.
echo hello
echo%nl%
REM without space ^^^
echo World
结果:
hello
world