CMD / windows batch: how to pass double quote and more character in command argument?

I can pass a double quote and more than a character to any command in several ways: '"' , "\"" , ">"

But when I try to transfer them together

 C:\>echo "\">" The system cannot find the path specified. 

Same thing with "\"\>" . I could make it work with single quotes, but since I already have so much work with quotes, I would like to keep all this inside double quotes.

Is there any way to avoid this?

I'm on windows7, but I think this is some kind of backward compatibility feature, so I'm not sure if this information matters.

Change 1:

I had Endoro's correct answer ... but it is not so simple. CMD treats ^> differently depending on whether there is a hidden double quote in the string. Does anyone know why ?! or another way of shielding?

 C:\>sh echo "\"^>" "> C:\>sh echo "a^>" a^> C:\>echo "\"^>" "\">" C:\>echo "a^>" "a^>" 

Edit 2: here are sample tests for what Monacraft suggested, using ^ before quotes that go around the string

 C:\>echo ^"a/>" The system cannot find the path specified. (we still need to escape that > symbol) C:\>echo ^"a/^>" "a/>" (work fine without \" in the string) C:\>echo ^"\"/^>" "\"/^>" (add a single \" and the ^> escaping stop to works) C:\>echo ^""/^>" ""/^>" (ok, using ^ before the string means i dont have to escape the " anymore) C:\>echo ^"^\"/^>" "\"/^>" (but what if i have an actual \" in my input that i have to escape... would ^\ prevent this from happening? nope) 
+4
source share
1 answer

OK, I canโ€™t give you a full explanation, but if you put an escape character in front of double quotes, it will work:

 C:\>echo "a^>" "a^>" C:\>echo ^"a^>" "a>" 

I think putting ^ in front of the line, your cmd command will not process ^ inside the line as part of the actual line. That's why:

 C:\>echo "text^>" ^"text^>" "text^>" "text>" 

It. However, I cannot give you a full explanation, but at least it solves your problem.

Edit 2:

Ok, for editing 2 All I can say is that you don't need to hide anything inside the line!

 C:\>echo ^"\"/>" "\"/>" 

This website has also been found which explains that to avoid \ all you need is \\ . Click here for more information. For " just double quotation marks ( "" ).

+2
source

Source: https://habr.com/ru/post/1499454/


All Articles