Search code examples
batch-filespecial-characters

Difference between Echo[Special Character]


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]?


Solution

  • 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(