07-23-2023, 10:48 AM
I can pass a double quote, and a larger than sign to any command in several ways: `'"'`, `"\""`, `">"`
But when i try to pass them together
C:\>echo "\">"
The system cannot find the path specified.
Same with `"\"\>"`. I could make it work with single quotes around, but since i already have so much going on with dealing with quotes i'd like to keep it all inside double quotes.
Is there any way to escape that?
I'm on windows7 but i believe this is some backward compatibility 'feature', so not sure this info is relevant.
Edit 1:
I tought Endoro had the right answer... but it's not that simple. CMD treats `^>` differently depending if there's a escaped double quote in the string. Anyone have any idea why?! or a different escaping method?
C:\>sh echo "\"^>"
">
C:\>sh echo "a^>"
a^>
C:\>echo "\"^>"
"\">"
C:\>echo "a^>"
"a^>"
Edit 2:
here are the tests cases for what Monacraft suggested, using `^` before the 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)
But when i try to pass them together
C:\>echo "\">"
The system cannot find the path specified.
Same with `"\"\>"`. I could make it work with single quotes around, but since i already have so much going on with dealing with quotes i'd like to keep it all inside double quotes.
Is there any way to escape that?
I'm on windows7 but i believe this is some backward compatibility 'feature', so not sure this info is relevant.
Edit 1:
I tought Endoro had the right answer... but it's not that simple. CMD treats `^>` differently depending if there's a escaped double quote in the string. Anyone have any idea why?! or a different escaping method?
C:\>sh echo "\"^>"
">
C:\>sh echo "a^>"
a^>
C:\>echo "\"^>"
"\">"
C:\>echo "a^>"
"a^>"
Edit 2:
here are the tests cases for what Monacraft suggested, using `^` before the 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)