"echo" VS "echo." VS "echo:"?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nitt
Posts: 218
Joined: 22 Apr 2011 02:43

"echo" VS "echo." VS "echo:"?

#1 Post by nitt » 02 Jun 2011 18:17

What's the difference between ECHO:, ECHO., and ECHO? They all seem to do the same thing for me...

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: "echo" VS "echo." VS "echo:"?

#2 Post by Ed Dyreen » 02 Jun 2011 18:37

There is definetly a difference, but don't worry about it too much, it only fails on rare occasions.

There is a good thread around here, can't find it :oops:

sorry nitt, @dbenham would find it immediately, I don't know all this out of my head..

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: "echo" VS "echo." VS "echo:"?

#3 Post by Ed Dyreen » 02 Jun 2011 18:46

Got it :)
Problem with delayed expansion after ECHO. or ECHO: :arrow:
http://www.dostips.com/forum/viewtopic.php?f=3&t=1855&p=7557&hilit=echo+fails#p7557

Post ECHO. FAILS to give text or blank line - Instead use ECHO/ :arrow:
http://www.dostips.com/forum/viewtopic.php?f=3&t=774&start=0

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: "echo" VS "echo." VS "echo:"?

#4 Post by dbenham » 02 Jun 2011 19:13

It all stems from people wanting to echo a blank line.
There is a huge difference between:

Code: Select all

ECHO
and all other forms (not an exhaustive list):

Code: Select all

ECHO.
ECHO:
ECHO(

ECHO by itself will print either "ECHO is on" or "ECHO is off". The others echo a blank line. But what do you do if you ECHO %variable% and the variable may be undefined? You want a blank line in those cases so you issue ECHO.%variable% instead. But under rare conditions the various characters following the ECHO cause problems. See ECHO. FAILS to give text or blank line - Instead use ECHO/ for details.

Based on my interpretation of the info on the thread - no one has discovered the perfect solution that is guaranteed to work in all situations. But people had gone years (decades?! I think I remember this back in the 1980s ) believing that ECHO. was a fine solution before the above thread pointed out problems. Will you ever run into the problem? Probably not, but...

Dave Benham

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: "echo" VS "echo." VS "echo:"?

#5 Post by Ed Dyreen » 02 Jun 2011 19:20

and when you do run into problems with echo. use echo: :)

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: "echo" VS "echo." VS "echo:"?

#6 Post by orange_batch » 02 Jun 2011 20:11

Read the second link Ed posted if you want, it explains it.

I choose to use echo: as a personal preference. I think based on that thread's tests it's not the absolute best choice because of very very rare if not impossible conflicts depending on what you choose to echo (a problem I don't have), but it's in the second-best tier.

-if I remember correctly, it's one of the choices that's faster than regular echo
-I don't need to use more than one form of echo (like echo and echo.) I just echo: whether it's text or a blank line.
-comments are prefixed with :: so there's some uniformity there. besides, colons are like ol' RPG-style dialogue

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: "echo" VS "echo." VS "echo:"?

#7 Post by jeb » 03 Jun 2011 03:53

I choose echo(, as it solves the most problems.
I expect that the echo work as expected for following task
- create an empty line
- outputs a (delayed) variable, even if it is empty
- outputs a (delayed) variable, even if it uses replace operator or substring features
- outputs a variable independent of the content like "/?" or "/../myBat.bat"


Code: Select all

@echo off
setlocal Enabledelayedexpansion
rem setlocal DisbaleExtensions
echo echo Failure in "%%~0" > myBat.bat
echo > echo
set "emptyVar="
set "var=\..\myBat.bat"
set "questionMark=/?"

echo ###### Test echo(
echo The next two lines should be empty
echo(
echo(!emptyLine!
echo(!var:~1,3!
echo(!var!
echo(!questionMark!
echo(

echo ###### Test echo.
echo The next line should be empty
call :testEchoDot
echo(

echo ###### Test echo:
echo The next line should be empty
echo:
echo:!emptyLine!
echo:!var:~1,3!
echo:!var!
echo:!questionMark!
goto :eof

:testEchoDot
echo.
echo.!emptyLine!
echo.!var:~1,3!
echo.!var!
echo.!questionMark!
goto :eof


OUTPUT

Code: Select all

###### Test echo(
The next two lines should be empty


..\
\..\myBat.bat
/?

###### Test echo.
The next line should be empty
Der Befehl "echo." ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
Der Befehl "echo." ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
var:~1,3
Failure in "echo.\..\myBat.bat"

###### Test echo:
The next line should be empty


var:~1,3
Failure in "echo:\..\myBat.bat"


jeb

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: "echo" VS "echo." VS "echo:"?

#8 Post by Ed Dyreen » 03 Jun 2011 04:18

I voted for u jeb 8)

How many times will we have to say thanks again ?

THANKS

It does looks dangerous though, I am a little afraid of using it in complex macros..

Post Reply