windows 批处理文件设置双引号一个变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7029975/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:48:46  来源:igfitidea点击:

Batch file setting double quote a variable

windowscommand-linebatch-file

提问by odez213

In a Windows XP .bat file, how do I set a variable value to use double quote? I couldn't find special characters for batch file.

在 Windows XP .bat 文件中,如何设置变量值以使用双引号?我找不到批处理文件的特殊字符。

SET myVariable= " \"myValue \" "

回答by Andriy M

You can use the method @Patrick Cuff has offered or you can do it quite simply:

您可以使用@Patrick Cuff 提供的方法,也可以非常简单地完成:

SET var="Value"

Let's see if it works...

让我们看看它是否有效...

ECHO %var%

and the output is:

输出是:

"Value"

Yes! :)

是的!:)

回答by Patrick Cuff

If this is for Windows, you need to escape the double quotes with a caret (^):

如果这是用于 Windows,则需要使用脱字符 ( ^)对双引号进行转义:

set myVariable=^"myVlaue^"

Putting single quotes around the value won't work, the value will include the single and double quotes.

在值周围放置单引号不起作用,该值将包括单引号和双引号。

回答by tangens

You can use

您可以使用

SET myVariable='"myValue"'