windows BATCH:如何将包含“&”字符的字符串回显到文件中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8319009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
BATCH: How to echo string containing '&' char to a file
提问by orshachar
I'm trying to write to a file a URL string that has the '&' char in it (using simple 'echo'), problem is that it's a saved char in the command prompt so it fails.
我正在尝试将一个包含“&”字符的 URL 字符串写入文件(使用简单的“echo”),问题是它是命令提示符中保存的字符,因此失败。
Is there any way to tell the command prompt that it's part of the string.
有什么方法可以告诉命令提示符它是字符串的一部分。
Example:
例子:
echo www.google.com/search=make&peace > love.txt
I'll get an error indicating that "peace" is not a recognized command.
我会收到一条错误消息,指出“和平”不是公认的命令。
Thanks!
谢谢!
回答by Cat Plus Plus
cmd uses ^ as the escape character, so
cmd 使用 ^ 作为转义字符,所以
echo www.google.com/search=make^&peace > love.txt
回答by rkokkelk
Just enclose the URL in Quotes:
只需将 URL 包含在引号中:
echo "www.google.com/search=make&peace" > love.txt