Difference between Echo[Special Character]

扶醉桌前 提交于 2019-12-11 00:55:00

问题


When writing batch files, I found out some people uses Echo.,Echo/,Echo( etc...These echo a blank line, so what is the difference between these Echo[Special Character]?


回答1:


You can use many different characters with echo. One of .[]+\:/,;=(.

But there are multiple requirements for a good choice.

  1. It should create an empty line (not ECHO iS OFF)

    1. It should be able to output any content if used with a (delayed) variable
    2. It shouldn't fail when a special namend file exists in the current directory

The first point works for all characters (from the list).
The second point fails for \:. with content like \..\..\..\windows\system32\calc.exe

@echo off
setlocal EnableDelayedExpansion
set var=\..\..\..\windows\system32\calc.exe
echo.!var!

,;= fails with /? and / fails with ?

@echo off
setlocal EnableDelayedExpansion
set var=/?
echo=!var!

The third point fails for .[]+

echo echo HELLO FROM %~f0 > echo[.bat
echo[ This fails

The only one that works always is echo(



来源:https://stackoverflow.com/questions/41647005/difference-between-echospecial-character

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