使用unix换行符在窗口上回显文件

时间:2012-03-26 16:55:47

标签: windows echo

有没有办法解决这个问题:

echo test line > t.txt

在Windows批处理文件或makefile中运行使用unix行结尾(\n)而不是windows one(\r\n)?

2 个答案:

答案 0 :(得分:1)

不,你不能使用echo来做。 Echo只需编写一行文本后跟一个CR / LF对(Windows行结束符)即可。重定向到文件只会将该行文本发送到文件句柄而不是stdout。无法修改使用的行结束字符。

答案 1 :(得分:1)

结合此处Windows batch: echo without new line和此处Is it possible to put a new line character in an echo line in a batch file?

的答案
SET LF=^


REM important to have two blank lines after the SET command
<NUL set /p=test line^%LF%%LF%> t.txt