#1 27 Dec 2015 13:48

Eehixohw
Member
Registered: 25 Sep 2011
Posts: 40

echo vs echo.

What is the difference between writing
echo I am here

and
echo. I am here

They seem the same.

Offline

#2 27 Dec 2015 15:23

Nexusfactor
Member
Registered: 15 Dec 2015
Posts: 8

Re: echo vs echo.

Check this page out, they explain the differences. http://www.dostips.com/forum/viewtopic.php?t=1900

Offline

#3 29 Dec 2015 17:54

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,126

Re: echo vs echo.

Drilling into Nexusfactor's link, I wouldn't recommend "echo."; I've used "echo:" since DOS days with no ill effects (yet).

To illustrate the difference, consider:

@echo off
set "var=hello world"
echo %var%
set "var="
echo %var%
echo on
echo too chatty now

@echo off
set "var=hello world"
echo:%var%
set "var="
echo:%var%
echo:on
echo:Not too chatty

When %var% is blank, it's equivalent to doing just "echo" as a command, which will show you the state of echo;  "off" and "on" are reserved words for "echo" (when a space is used as separator) and if used in isolation will be parsed and acted upon.


cmd | *sh | ruby | chef

Offline

#4 29 Dec 2015 19:49

Aacini
Member
Registered: 05 Dec 2012
Posts: 149

Re: echo vs echo.

About the difference between "echo String" and "echo.String", I wrote this program:

@echo off
setlocal

set "start=%time%"
for /L %%i in (1,1,1000) do call :echoSpace
set "middle=%time%"
for /L %%i in (1,1,1000) do call :echoDot
set "end=%time%"

echo/
echo Start:  %start%
echo Middle: %middle%
echo End:    %end%

goto :EOF


:echoSpace
echo I am here
exit /B

:echoDot
echo.I am here
exit /B

I run this program three times; this is the output plus elapsed times I added at hand:

			echo String	echo.String

Start:  12:24:13.08
Middle: 12:24:20.06	6.98
End:    12:24:31.20			11.14

Start:  12:27:02.09
Middle: 12:27:09.04	6.95
End:    12:27:20.05			11.01

Start:  12:27:39.93
Middle: 12:27:46.82	6.89
End:    12:27:57.81			10.99

Average:		6.94		11.05

In conclusion: "echo.String" run 60% slower than "echo String"

Antonio

Offline

#5 30 Dec 2015 12:17

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 446

Re: echo vs echo.

using echo. could lead to an unexpected errors as the dot is accepted symbol for file name.
If you have file named echo. in the path or in the same directory and try echo. something you'll see an error.

This was found by jeb but I cant find the thread.

also \  / + ( [ ] have the same behavior as the dot with echo - though jeb's suggested that echo/ and echo( are the safest because ( and \ cannot be part of filename or a path. Though I dont know about the performance.

Offline

#6 30 Dec 2015 13:37

RG
Member
From: Minnesota
Registered: 18 Feb 2010
Posts: 361

Re: echo vs echo.

Using Aacini's test (above)... performance using echo( is even a bit better than echo  (echo space). Presumably echo. is slower because it checks for file by that name first.


Windows Shell Scripting and InstallShield

Offline

#7 30 Dec 2015 19:16

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,108
Website

Re: echo vs echo.

Heres an older newsgroup thread with ECHO's 'hidden dangers' and a comparison of performance:

https://groups.google.com/forum/?hl=en# … -C8ViGOD0J

Conclusion
It's interesting that the colon and slashes stop CMD iterating the PATH. These are all illegal filename characters so I guess CMD just doesn't bother.

So, what's the best character to use? Given that your scripts will be more reliable if using some kind of character immediately after ECHO, you may as well use one that gives the best all-round performance under all conditions
and doesn't introduce new problems. That definitely rules out the period. The forward slash is clearly the best performer, hotly pursued by the colon and backslash.

I  going to continue with the colon, its what I've been using for the last few months. For all the new blood out there, if you want the fastest scripts then the forward slash is the way to go.

--
Ritchie

Offline

#8 30 Dec 2015 23:13

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,126

Re: echo vs echo.

npocmaka wrote:

echo/ and echo( are the safest because ( and \ cannot be part of filename or a path

"(" and ")" can form part of a file/path...

X:\x>dir /b/s
X:\x\(hello)
X:\x\(hello)\(world)

cmd | *sh | ruby | chef

Offline

#9 31 Dec 2015 10:03

jeb
Member
From: Germany
Registered: 19 Nov 2010
Posts: 109

Re: echo vs echo.

bluesxman wrote:

Drilling into Nexusfactor's link, I wouldn't recommend "echo."; I've used "echo:" since DOS days with no ill effects (yet).

Even echo: fails, see this example.

setlocal EnableDelayedExpansion
set "var=..\..\..\..\Windows\System32\calc.exe"
echo:!var!

A discussion about the various echo forms can be found at dostips ECHO. FAILS to give text or blank line

"(" and ")" can form part of a file/path...

But echo( will no be handled as filename, it seems that parser splits the "(" in an early phase and detects that the echo is an internal command.

Offline

Board footer

Powered by FluxBB