我需要将包含尖括号(<和>)的字符串回显到Windows计算机上的文件.基本上我想做的是以下内容:
echo some string < with angle > brackets >>myfile.txt
这不起作用,因为命令解释器与尖括号混淆.我可以像这样引用整个字符串:
echo "some string < with angle > brackets" >>myfile.txt
但后来我的文件中有双引号,我不想要.
转义括号ala unix也不起作用:
echo some string \< with angle \> brackets >>myfile.txt
想法?
这可能很容易,但网上没有答案.我想通过批处理将XML行回显到文件中,但它误解了重定向">"的XML结束标记.该行如下:
echo <?xml version="1.0" encoding="utf-8" ?> > myfile.xml
Run Code Online (Sandbox Code Playgroud)
是否有任何方法可以提示批量解析器不解释特殊字符串?我使用双引号但它也将它们写入文件!echo之后文件应如下所示:
<?xml version="1.0" encoding="utf-8" ?>
Run Code Online (Sandbox Code Playgroud) 这应该生成具有不同文件的Web文档的层次结构,这是因为我很懒,我做了这个.
@echo off
echo.
echo This program will generate the base folder for a new website .. .
pause
md folders
echo > folders/default.html "<html> /* More content */ </html>"
echo > folders/style.css " /* All the standards i always use */ "
echo > folders/javascript.js " /* All the standards i always use */ "
echo.
exit
Run Code Online (Sandbox Code Playgroud)
它也有效,但问题是,我不能删除/逃避引号,但这给了歇斯底里的时刻.
我尝试了很多不同的东西.用类型改变回声,我尝试了我可以在www等上找到的不同的转义选项,但引号仍然存在.
我想使用 CMD 批处理文件将最简单的标签添加到文件中,但双引号似乎破坏了聚会:
\n\n从其他 StackOverflow 帖子中,我知道双引号状态机和 ^" (^ 作为转义字符)的用法。但我仍然无法使其工作:
\n以下是我的尝试(及其结果):
C:\\>echo <tag variable="value"> // very na\xc3\xafve\nThe syntax of the command is incorrect.\n\nC:\\>echo "<tag variable="value">" // let\'s use quotes for delimiting the string\n"<tag variable="value">"\n\nC:\\>echo "<tag variable=^"value^">" // let\'s use the escape character\nThe system cannot find the path specified.\n\nC:\\>echo "<tag variable=^"value^"> // what if the state machine is not switched back?\nThe syntax of the command is incorrect.\n\nC:\\>echo "<tag variable=^"value"> // desperate people do weird things :-)\n"<tag variable=^"value">\nRun Code Online (Sandbox Code Playgroud)\n\n我还使用标签字符 < …