"echo" VS "echo." VS "echo:"?
Moderator: DosItHelp
"echo" VS "echo." VS "echo:"?
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:"?
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..
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:"?
Got it
Problem with delayed expansion after ECHO. or ECHO:
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/
http://www.dostips.com/forum/viewtopic.php?f=3&t=774&start=0
Problem with delayed expansion after ECHO. or ECHO:
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/
http://www.dostips.com/forum/viewtopic.php?f=3&t=774&start=0
Re: "echo" VS "echo." VS "echo:"?
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
There is a huge difference between:
Code: Select all
ECHO
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
Re: "echo" VS "echo." VS "echo:"?
and when you do run into problems with echo. use echo:
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: "echo" VS "echo." VS "echo:"?
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
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:"?
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"
OUTPUT
jeb
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:"?
I voted for u jeb
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..
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..