Page 1 of 1
"echo" VS "echo." VS "echo:"?
Posted: 02 Jun 2011 18:17
by nitt
What's the difference between ECHO:, ECHO., and ECHO? They all seem to do the same thing for me...
Re: "echo" VS "echo." VS "echo:"?
Posted: 02 Jun 2011 18:37
by Ed Dyreen
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
sorry nitt, @dbenham would find it immediately, I don't know all this out of my head..
Re: "echo" VS "echo." VS "echo:"?
Posted: 02 Jun 2011 18:46
by Ed Dyreen
Re: "echo" VS "echo." VS "echo:"?
Posted: 02 Jun 2011 19:13
by dbenham
It all stems from people wanting to echo a blank line.
There is a huge difference between:
and all other forms (not an exhaustive list):
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
Re: "echo" VS "echo." VS "echo:"?
Posted: 02 Jun 2011 19:20
by Ed Dyreen
and when you do run into problems with echo. use echo:
Re: "echo" VS "echo." VS "echo:"?
Posted: 02 Jun 2011 20:11
by orange_batch
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
Re: "echo" VS "echo." VS "echo:"?
Posted: 03 Jun 2011 03:53
by jeb
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
Re: "echo" VS "echo." VS "echo:"?
Posted: 03 Jun 2011 04:18
by Ed Dyreen
I voted for u jeb
How many times will we have to say thanks again ?
THANKSIt does looks dangerous though, I am a little afraid of using it in complex macros..