2

I would like to add the simpliest tag into a file, using a CMD batchfile, but it seems that the double quotes are spoiling the party:

From other StackOverflow posts I am aware of the double quote state machine and the usage of ^" (^ as an escape character). Still I can't make it work:
Hereby my attempts (with their results):

C:\>echo <tag variable="value">  // very naïve
The syntax of the command is incorrect.

C:\>echo "<tag variable="value">"  // let's use quotes for delimiting the string
"<tag variable="value">"

C:\>echo "<tag variable=^"value^">" // let's use the escape character
The system cannot find the path specified.

C:\>echo "<tag variable=^"value^"> // what if the state machine is not switched back?
The syntax of the command is incorrect.

C:\>echo "<tag variable=^"value"> // desperate people do weird things :-)
"<tag variable=^"value">

I have also done some tests using the escape character in front of the tag characters < and > (as those have their own significance in CMD) but also there no good results.
Also first putting the entry within a variable (set test="...") does not solve the issue.
As mentioned, I am getting desperate. The only thing I want to do is writing this into a text file:

<tag variable="value">

Can anybody help me out here?
Thanks in advance

Dominique
  • 16,450
  • 15
  • 56
  • 112

3 Answers3

5

the characters you want to escape are not the " but the <.
Then the correct syntax is this one :

C:\>echo ^<tag variable="value"^>
Stephan
  • 53,940
  • 10
  • 58
  • 91
Mathiou
  • 399
  • 2
  • 12
1

Shouldn't you use the "\" char to escape a double quote ? Like "echo "< tag blabla=\"value\" >" ?

EDIT

Seems like :

echo ^<tag variable=^"value^"^> 

works fine !

Alexandre Beaudet
  • 2,774
  • 2
  • 20
  • 29
  • 1
    Although your proposal is correct, the escaping of the double quotes is unnecessary, as mentioned by Mathiou. – Dominique Oct 08 '15 at 12:24
-1

try with delayed expansion:

setlocal enableDelayedExpansion
set "tag_line=<tag variable="value">"
echo !tag_line!
npocmaka
  • 55,367
  • 18
  • 148
  • 187