[英]CMD/windows Batch: how to pass a double quote and a larger than sign in a command argument?
我可以用幾種方式傳遞一個雙引號和一個大於號的符號: '"'
, "\\""
, ">"
但是當我試圖將它們傳遞到一起時
C:\>echo "\">"
The system cannot find the path specified.
與"\\"\\>"
。我可以使用單引號,但由於我已經有很多處理引號,我想將它全部保留在雙引號內。
有什么方法可以逃脫嗎?
我在windows7上,但我相信這是一個向后兼容的“功能”,所以不確定這些信息是否相關。
編輯1:
我認為恩多羅有正確的答案......但事情並非那么簡單。 CMD會根據字符串中是否存在轉義雙引號來區別對待^>
。 任何人都知道為什么?! 還是一種不同的逃避方法?
C:\>sh echo "\"^>"
">
C:\>sh echo "a^>"
a^>
C:\>echo "\"^>"
"\">"
C:\>echo "a^>"
"a^>"
編輯2:這是Monacraft建議的測試用例,在字符串周圍的引號之前使用^
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)
好的,我不能給你一個完整的解釋,但如果你在雙引號之前放一個轉義字符就可以了:
C:\>echo "a^>"
"a^>"
C:\>echo ^"a^>"
"a>"
我想通過在字符串之前放置一個^
,告訴cmd不要將字符串中的^
視為實際字符串的一部分。 這就是為什么:
C:\>echo "text^>" ^"text^>"
"text^>" "text>"
那樣做。 但是,我不能給你一個完整的解釋,但至少可以解決你的問題。
好的,編輯2我只能說你不需要逃避字符串內的任何東西!
C:\>echo ^"\"/>"
"\"/>"
還發現這個網站解釋說要逃避\\
所有你需要的是\\\\
。 點擊此處獲取更多信息。 對於"
簡單地加倍引號( ""
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.