如何使用命令提示符 echo 命令用双引号写一个 XML 标签

How to write an XML tag with double quotes using command prompt echo command

我想使用 CMD 批处理文件将最简单的标记添加到文件中,但双引号似乎破坏了派对:

从其他 Whosebug 帖子中,我知道双引号状态机和 ^"(^ 作为转义字符)的用法。但我仍然无法使其工作:
特此我的尝试(及其结果):

C:\>echo <tag variable="value">  // very naïve
The syntax of the command is incorrect.

C:\>echo "<tag variable="value">"  // let's use quotes for delimiting the string
"<tag variable="value">"

C:\>echo "<tag variable=^"value^">" // let's use the escape character
The system cannot find the path specified.

C:\>echo "<tag variable=^"value^"> // what if the state machine is not switched back?
The syntax of the command is incorrect.

C:\>echo "<tag variable=^"value"> // desperate people do weird things :-)
"<tag variable=^"value">

我也做了一些测试,在标签字符 < 和 > 前面使用转义字符(因为它们在 CMD 中有自己的意义),但也没有很好的结果。
此外,首先将条目放入变量 (set test="...") 中并不能解决问题。
如前所述,我越来越绝望了。我唯一想做的就是将其写入文本文件:

<tag variable="value">

有人可以帮我吗?
提前致谢

你不应该使用“\”字符来转义双引号吗? 喜欢 "echo "< tag blabla=\"value\" >" ?

编辑

好像是:

echo ^<tag variable=^"value^"^> 

工作正常!

您要转义的字符不是 " 而是 <.
那么正确的语法是这个:

C:\>echo ^<tag variable="value"^>

试试 delayed expansion:

setlocal enableDelayedExpansion
set "tag_line=<tag variable="value">"
echo !tag_line!