Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
900 views
in Technique[技术] by (71.8m points)

batch file - How to write an XML tag with double quotes using command prompt echo command

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...