转义以正斜杠和问号开头的批处理文件回显

发布于 2024-11-17 18:12:06 字数 579 浏览 10 评论 0原文

有点棘手。如何在批处理文件中正确转义以下内容?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两个我 2024-11-24 18:12:06

对于转义 echo 参数,存在许多变体,例如 echo.echo:echo=
但只有 echo( 似乎对任何附加文本都是安全的。

如果存在像 echoecho[这样的文件,这些就会失败。 echo]echo+

echo.
echo[
echo]
echo+

如果当前目录中存在名为 my.bat 的文件,则这些失败,

echo\..\my.bat
echo:\..\my.bat
echo.\..\my.bat

这些失败独立于文件

echo/?
echo,/?
echo;/?

只有 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] or echo+

echo.
echo[
echo]
echo+

These one fails, if a file in the current directory exists named my.bat

echo\..\my.bat
echo:\..\my.bat
echo.\..\my.bat

These one fails independet of a file

echo/?
echo,/?
echo;/?

Only the echo( seems to be always safe against any content

治碍 2024-11-24 18:12:06

要转义 echo 参数,您可以使用替代语法 echo.

echo./?

For escaping echo arguments, you can use the alternative syntax echo.:

echo./?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文