2

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

  • 3
    http://www.dostips.com/forum/viewtopic.php?t=1900 – Squashman Jan 14 '17 at 06:01
  • 4
    Or read forum topic [ECHO. FAILS to give text or blank line - Instead use ECHO/](http://www.dostips.com/forum/viewtopic.php?f=3&t=774) also on dostips.com. – Mofi Jan 14 '17 at 08:47
  • Related: [What does an echo followed immediately by a slash do in a Windows CMD file?](http://stackoverflow.com/q/41514776) – aschipfl Jan 14 '17 at 11:41

1 Answers1

6

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(

jeb
  • 78,592
  • 17
  • 171
  • 225
  • Does `echo/` really fail with `/?`? I think it only fails with `?`... +1 anyway! – aschipfl Jan 14 '17 at 15:24
  • `echo( ` always give me this error: `echo( is not an internal............... ` ( testing on Win7 64 bits) –  Jan 16 '17 at 09:32
  • @SteveFest That's very curious, `echo(` runs on many systems and I never heard, that it fails. It works directly on the command line as also in a batch file – jeb Jan 16 '17 at 11:35
  • 2
    @SteveFest Are you sure, that your batch file is ANSI encoded? Does any other command work in the file? – jeb Jan 16 '17 at 11:38
  • 2
    @SteveFest, `echo(` does work, unless you are using it immediately after a `:Label` within a parenthesised block of code, which is in fact caused by the label handling... – aschipfl Jan 16 '17 at 11:38