echo vs echo. vs echo:

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

echo vs echo. vs echo:

Post by MigrationUser »

27 Dec 2015 13:48
Eehixohw

What is the difference between writing
echo I am here

and
echo. I am here

They seem the same.

----------------------------

#2 27 Dec 2015 15:23
Nexusfactor

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

----------------------------

#3 29 Dec 2015 17:54
bluesxman

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:

Code: Select all

@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

----------------------------

#4 29 Dec 2015 19:49
Aacini

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

Code: Select all

@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:

Code: Select all

			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

----------------------------

#5 30 Dec 2015 12:17
npocmaka

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.

----------------------------

#6 30 Dec 2015 13:37
RG

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

----------------------------

#7 30 Dec 2015 19:16
Simon Sheppard

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

#8 30 Dec 2015 23:13
bluesxman
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...

Code: Select all

X:\x>dir /b/s
X:\x\(hello)
X:\x\(hello)\(world)
cmd | *sh | ruby | chef

----------------------------

#9 31 Dec 2015 10:03
jeb
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.

Code: Select all

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.
Post Reply