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

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

问题描述

这也许很容易,但有过网没有答案吧。我想呼应通过批处理一个XML行成一个文件,但它误解了XML结束标记重定向>。行如下:

 回声< XML版本=1.0编码=UTF-8&GT?; >将myfile.xml

有没有办法给一个提示一批解析器不跨preT特殊字符串?我用双引号,但其写入文件,以及!该文件应该是这样的回应后:

 <?XML版本=1.0编码=UTF-8&GT?;


解决方案

您可以逃脱shell元字符与 ^

 回音^< XML版本=1.0编码=UTF-8^&GT?; >将myfile.xml

请注意,由于回声是一个shell内置它不遵循有关报价通常约定,所以只引用参数将输出的报价,而不是删除它们

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" ?>

解决方案

You can escape shell metacharacters with ^:

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

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天全站免登陆