cmd escape character ^
cmd转义字符
A caret (^) character in a command line means that the character immediately following it is interpreted literally
^字符可以用来在命令行中用来转义,一个例子
to set the output of var into a variable without creating a temp file, go a bit more complex with:
for /f "delims=" %a in ('ver ^| findstr /v "linux"') do @set myvar=%a
check it with:
echo %myvar%
上面的例子中, ver ^| 转义了|,告诉cmd这个命令ver ^| findstr /v "linux" 是一个完整的命令, 这样shell就不会将for /f "delims=" %a in ('ver ^认为是一个将标准输出重定向到findstr /v "linux"') do @set myvar=%a标准输入的命令了。
find more on the caret command
更多的关于^的内容, 请看 Batch: Escaping with caret 和How to avoid cmd.exe interpreting shell special characters like <> ^.
References
How to avoid cmd.exe interpreting shell special characters like <> ^

本文详细介绍了CMD命令行中如何使用^字符进行转义操作,包括具体的语法示例及应用场景,帮助读者理解如何避免特殊字符被误解析。
8万+

被折叠的 条评论
为什么被折叠?



