Windows批处理(.bat)脚本中带有Unix行尾的回显文本 [英] Echo text with Unix line endings from a Windows batch (.bat) script

查看:256
本文介绍了Windows批处理(.bat)脚本中带有Unix行尾的回显文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有以下批处理脚本:

Say I have the following batch script:

For ... DO (
SET VAL=%%B
IF defined VAL echo %%A=%%B >> %OUTPUT_FILEPATH%
)

如何使用Unix(仅换行)行尾来输出echo?

How could I get the echo to output using Unix (just line feed) line endings?

或者,我可以原样编写文件,然后再从批处理脚本转换文件吗? (某种查找/r/n并替换为/n?如果是这样,我该怎么做?)

Alternatively, could I write the file as-is then convert it from the batch script afterwards? (some kind of find /r/n and replace with /n? If so, how would I do that?)

我想要一个独立的解决方案(即不涉及下载额外的实用程序,并且可以从批处理脚本本身[Windows 7]中完成).

I'd like a self-contained solution (i.e. one that doesn't involve downloading extra utilities, and can be done from within the batch script itself [Windows 7]).

推荐答案

来自 格式化很棘手​​,但是请尝试

Formatting is tricky, but try

set ^"LF=^

^" Don't remove previous line & rem line feed (newline)
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"& rem Define newline with line continuation

For ... DO (
SET VAL=%%B
IF defined VAL <nul set/P^=%%A=%%B%\n%>> %OUTPUT_FILEPATH%
)

或者,为了避免在第一行之后出现空格:

Or, to avoid the leading space after first line:

<nul set/P^=%%A=%%B%\n%^>> %OUTPUT_FILEPATH%

这篇关于Windows批处理(.bat)脚本中带有Unix行尾的回显文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆