ECHO. FAILS to give text or blank line - Instead use ECHO/

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#16 Post by amel27 » 20 Jan 2011 07:28

jeb wrote:No it starts only once, the second delay is in the echo %%a itself.
Yes, I understand... Thanks again!
Unfortunately, I gave out wished for the valid. It turns out that substitution doesn't work for new CMD call... :(

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

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#17 Post by jeb » 20 Jan 2011 17:23

amel27 wrote:Unfortunately, I gave out wished for the valid. It turns out that substitution doesn't work for new CMD call... :(
Delayed Expansion can work also in a new (indirect) CMD call, if it is turned on via registry keys.

I tried to explain these things here The Secrets Behind Batch File Interpretation

jeb

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

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#18 Post by dbenham » 16 Jun 2011 16:22

The echo:\..\my.bat behavior really blows my mind. :shock:
So NearlyAnyText\..\ is equivalent to .\ is equivalent to current directory.

dir Absolute:Gibberish+Nonsense\..\* gives a directory of the current directory. Two characters that can prevent this nonsense with the DIR command are ( and / (any others?)

Characters that prevent probelm with ECHO:xxxx\..\my.bat are ( / = ; + <space> (any others?)

Also usually a \ prior to \..\ will prevent the weird interpretation in both cases. But \.\..\ still has problems.
"DOS" never ceases to amaze :!:


jeb wrote:Ok, now we have a problem, there is only one usable character left.
The "(", which I agree with you, that this presumably has other side effects. :?

:?: So has anyone found any problems with ECHO(

The only problem I can find is the ECHO( command cannot be in a variable "macro" that is expanded with delayed expansion or FOR variable expansion. The other ECHO variants do not have this limitation. I find I can get around the limitation by using CALL ECHO(, but then some of the bugaboos of the other echo variants arise.

Code: Select all

@echo off
setlocal enableDelayedExpansion
cls
call :test "echo:"
call :test "echo."
call :test "echo("
call :test "call echo("
exit /b

:test
  echo ------------------------------
  echo cmd=%~1
  set "cmd=%~1"
  %cmd%Immediate expansion
  %cmd%!cmd:~0,4! Immediate expansion with delayed substring
  for /f "delims=" %%c in ("!cmd!") do %%cFOR variable expansion
  for /f "delims=" %%c in ("!cmd!") do %%c!cmd:~0,4! FOR variable expansion with delayed substring
  !cmd!Delayed expansion
  !cmd!!cmd:~0,4! Delayed expansion with delayed substring
exit /b

Output:

Code: Select all

------------------------------
cmd=echo:
Immediate expansion
cmd:~0,4 Immediate expansion with delayed substring
FOR variable expansion
cmd:~0,4 FOR variable expansion with delayed substring
Delayed expansion
cmd:~0,4 Delayed expansion with delayed substring
------------------------------
cmd=echo.
Immediate expansion
cmd:~0,4 Immediate expansion with delayed substring
FOR variable expansion
cmd:~0,4 FOR variable expansion with delayed substring
Delayed expansion
cmd:~0,4 Delayed expansion with delayed substring
------------------------------
cmd=echo(
Immediate expansion
echo Immediate expansion with delayed substring
'echo(FOR' is not recognized as an internal or external command,
operable program or batch file.
The filename, directory name, or volume label syntax is incorrect.
'echo(Delayed' is not recognized as an internal or external command,
operable program or batch file.
The filename, directory name, or volume label syntax is incorrect.
------------------------------
cmd=call echo(
Immediate expansion
call Immediate expansion with delayed substring
FOR variable expansion
cmd:~0,4 FOR variable expansion with delayed substring
Delayed expansion
cmd:~0,4 Delayed expansion with delayed substring


Dave Benham

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#19 Post by alan_b » 15 Jul 2011 05:42

I have started this topic, so I will finish it - or maybe not ! !

I believe these work-around are redundant on Windows 7.

I recognise expert contributions way above my skill level in this topic,
and would appreciate expert advice under my new topic
CMD.EXE and ECHO are Broken and fixed.
viewtopic.php?f=3&t=2053

Regards
Alan

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#20 Post by carlos » 15 Nov 2012 20:03

The info is very util. Thanks.

pyotr
Posts: 1
Joined: 28 May 2013 23:42

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#21 Post by pyotr » 28 May 2013 23:58

For what is is worth, I just ran accross this problem "ech not a valid command"

Code Sample
:WrongProg
color 47
Echo.
Echo Error - either wrong program or wrong computer
Echo.
Echo. Are We home?
set tag= "Wrong Drive maybe"
>> %LogFile% Echo. %tag%

It seems taht if you attempt to echo "error" it attempts to echo error, whcih confuses things.

Changing

Echo Error - either wrong program or wrong computer

to

Echo has Error - either wrong program or wrong computer

fixes that problem. Now if the rest will just cooperate...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#22 Post by foxidrive » 29 May 2013 04:54

pyotr wrote:For what is is worth, I just ran accross this problem "ech not a valid command"

Code Sample
:WrongProg
color 47
Echo.
Echo Error - either wrong program or wrong computer
Echo.
Echo. Are We home?
set tag= "Wrong Drive maybe"
>> %LogFile% Echo. %tag%


Did you forget to set logfile=something and the you created an echo. file in the same folder?

Try it again in an empty folder but set logfile=something

chrisroberts
Posts: 1
Joined: 26 Dec 2013 03:39

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#23 Post by chrisroberts » 26 Dec 2013 03:43

Thank you! This helps loads :mrgreen:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#24 Post by foxidrive » 26 Dec 2013 04:38

What did you find helpful about this?

penpen
Expert
Posts: 1988
Joined: 23 Jun 2013 06:15
Location: Germany

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#25 Post by penpen » 07 May 2014 06:03

dbenham wrote:
jeb wrote:Ok, now we have a problem, there is only one usable character left.
The "(", which I agree with you, that this presumably has other side effects. :?

:?: So has anyone found any problems with ECHO(

The only problem I can find is the ECHO( command cannot be in a variable "macro" that is expanded with delayed expansion or FOR variable expansion.
Only another easy to avoid problem, you cannot use "echo(" within a for loop after a "::"/":" line:

Code: Select all

@echo off
for %%a in (a) do (
   :: 123
   echo( 1
   echo( 2
   :123
   echo( 3
)
goto :eof

penpen

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

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#26 Post by dbenham » 07 May 2014 06:45

Very interesting find. You are right, easily avoided given that labels and label comments ought to be avoided within parentheses anyway.


Dave Benham

penpen
Expert
Posts: 1988
Joined: 23 Jun 2013 06:15
Location: Germany

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#27 Post by penpen » 07 May 2014 08:38

I've found a "workaround" (at least on my win xp home): ("^(\r)?\n(\r)?\n" seems to be a valid instruction that also may have paramters"):

Code: Select all

@echo off
for %%a in (a) do (
   :: 123
^

   this seems to be a parameter of "^(\r)?\n(\r)?\n" will never be executed
   echo( 1
   echo( 2
   :123
^


   echo( 3
)
^

this works outer for loops, too
(Strange... .)

penpen

Edit: Reminds me to the macro comments, but without the "<nul" part ... http://www.dostips.com/forum/viewtopic.php?f=3&t=5374.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#28 Post by foxidrive » 07 May 2014 09:40

It works in Win 8.1 too.

I'm also surprised

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

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#29 Post by dbenham » 08 May 2014 08:20

:shock: My brain hurts

The caret does not have to be at the beginning of the line.

Also, within parentheses, it only works as a comment if it follows a label or label comment. Outside of parentheses it can appear anywhere.

Code: Select all

@echo off
(
   :: Label comment
   ^

   Ignored if after a label comment within parentheses
   echo(1
   :label
   ^

   Also ignored if after a label comment within parentheses
   echo(2
   REM The empty "command" within parentheses  works OK without a preceding label if there is no comment included
   ^


   echo(3
   ^

   But this fails because it is within parentheses but does not follow a label
   echo(4
)
^

This is ignored outside of parentheses without a preceding label
:label
^

This is also ignored after a label
:: Label comment
^

And this is ignored after a label comment
echo Done


Dave Benham

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: ECHO. FAILS to give text or blank line - Instead use ECH

#30 Post by Liviu » 08 May 2014 11:13

penpen wrote:Reminds me to the macro comments, but without the "<nul" part.

Very interesting. Also reminds me of other label parsing craziness sighted at http://www.dostips.com/forum/viewtopic.php?f=3&t=3803.

Liviu

Post Reply