Escaping a batch file echo that starts with a forward slash and question mark

淺唱寂寞╮ 提交于 2020-01-28 00:07:34

问题


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.


回答1:


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

echo./?



回答2:


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



来源:https://stackoverflow.com/questions/6514746/escaping-a-batch-file-echo-that-starts-with-a-forward-slash-and-question-mark

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!