转义以正斜杠和问号开头的批处理文件回显
有点棘手。如何在批处理文件中正确转义以下内容?
echo /? display this help text
这种特殊的字符组合被视为“ECHO /?”命令:
C:\Batch>ECHO /? display this help text
Displays messages, or turns command-echoing on or off.
ECHO [ON | OFF]
ECHO [message]
Type ECHO without parameters to display the current echo setting.
它不响应插入符 (^) 转义,即。我试过了^/? /^?和 ^/^?。
注意:作为一种解决方法,我发现在中间插入其他字符足以绕过 ECHO 命令行处理器,例如:
echo ... /? display this help text
尽管如此,这并不理想,我想知道是否有一种方法可以实现所需的输出,即使用 /?在回显消息的开头。
Bit of a tricky one. How can I correctly escape the following in a batch file?
echo /? display this help text
This particular combination of characters is treated as an "ECHO /?" command:
C:\Batch>ECHO /? display this help text
Displays messages, or turns command-echoing on or off.
ECHO [ON | OFF]
ECHO [message]
Type ECHO without parameters to display the current echo setting.
It does not respond to caret (^) escaping, ie. I've tried ^/? /^? and ^/^?.
NB: As a workaround, I found that inserting other characters in between is enough to bypass the ECHO command line processor, eg:
echo ... /? display this help text
Still, this is not ideal and I wondered if there was a way to acheive the desired output, namely with /? at the start of the echoed message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于转义 echo 参数,存在许多变体,例如
echo.
、echo:
、echo=
但只有
echo(
似乎对任何附加文本都是安全的。如果存在像
echo
、echo[
、这样的文件,这些就会失败。 echo]
或echo+
如果当前目录中存在名为 my.bat 的文件,则这些失败,
这些失败独立于文件
只有
echo(
似乎始终安全防范任何内容For escaping echo arguments exists many variants, like
echo.
,echo:
,echo=
But only
echo(
seems to be secure against any appended text.These one fails, if files exists like
echo
,echo[
,echo]
orecho+
These one fails, if a file in the current directory exists named my.bat
These one fails independet of a file
Only the
echo(
seems to be always safe against any content要转义 echo 参数,您可以使用替代语法
echo.
:For escaping echo arguments, you can use the alternative syntax
echo.
: