Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file setting double quote a variable

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.

SET myVariable= " \"myValue \" "
like image 615
odez213 Avatar asked Aug 11 '11 17:08

odez213


People also ask

What is %% A in batch?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

How do you pass a parameter in a double quote?

Double quotes enable escaping through the use of the backslash (\). For example, if the special character semicolon is a value that is double-quoted, it should be represented as backslash semicolon (\;) so that the Integration Engine knows that the actual value (;) should be used.

How do you quote a variable?

When referencing a variable, it is generally advisable to enclose its name in double quotes. This prevents reinterpretation of all special characters within the quoted string -- except $, ` (backquote), and \ (escape).

How do you escape double quotes in DOS?

inside double-quoted strings, use `" or "" to escape double-quotes. inside single-quoted strings, use '' to escape single-quotes.


2 Answers

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

SET var="Value"

Let's see if it works...

ECHO %var%

and the output is:

"Value"

Yes! :)

like image 149
Andriy M Avatar answered Sep 28 '22 08:09

Andriy M


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

set myVariable=^"myVlaue^"

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

like image 26
Patrick Cuff Avatar answered Sep 28 '22 09:09

Patrick Cuff