使用带有特殊字符的批处理回显 [英] using batch echo with special characters

查看:22
本文介绍了使用带有特殊字符的批处理回显的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能真的很简单,但网上没有答案.我想通过批处理将 XML 行回显到文件中,但它误解了重定向的 XML 结束标记>".线路如下:

This maybe really easy but there were no answers for it over the net. I want to echo a XML line via batch into a file but it misunderstands the XML closing tag for redirection ">". The line is as follows:

echo <?xml version="1.0" encoding="utf-8" ?> > myfile.xml

有什么方法可以提示批处理解析器不要解释特殊字符串?我使用了双引号,但它也将它们写入文件!回显后文件应如下所示:

is there any way to give a hint to batch parser not to interpret a special string? I used double-quotes but it writes them to the file as well! The file should look like this after echo:

<?xml version="1.0" encoding="utf-8" ?>

推荐答案

您可以使用 ^ 转义 shell 元字符:

You can escape shell metacharacters with ^:

echo ^<?xml version="1.0" encoding="utf-8" ?^> > myfile.xml

请注意,由于 echo 是内置的 shell,它不遵循有关引用的通常约定,因此仅引用参数将输出引号而不是删除它们.

Note that since echo is a shell built-in it doesn't follow the usual conventions regarding quoting, so just quoting the argument will output the quotes instead of removing them.

这篇关于使用带有特殊字符的批处理回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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