Page 2 of 3

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

Posted: 20 Jan 2011 07:28
by amel27
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... :(

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

Posted: 20 Jan 2011 17:23
by jeb
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

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

Posted: 16 Jun 2011 16:22
by dbenham
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

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

Posted: 15 Jul 2011 05:42
by alan_b
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

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

Posted: 15 Nov 2012 20:03
by carlos
The info is very util. Thanks.

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

Posted: 28 May 2013 23:58
by pyotr
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...

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

Posted: 29 May 2013 04:54
by foxidrive
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

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

Posted: 26 Dec 2013 03:43
by chrisroberts
Thank you! This helps loads :mrgreen:

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

Posted: 26 Dec 2013 04:38
by foxidrive
What did you find helpful about this?

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

Posted: 07 May 2014 06:03
by penpen
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

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

Posted: 07 May 2014 06:45
by dbenham
Very interesting find. You are right, easily avoided given that labels and label comments ought to be avoided within parentheses anyway.


Dave Benham

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

Posted: 07 May 2014 08:38
by penpen
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.

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

Posted: 07 May 2014 09:40
by foxidrive
It works in Win 8.1 too.

I'm also surprised

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

Posted: 08 May 2014 08:20
by dbenham
: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

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

Posted: 08 May 2014 11:13
by Liviu
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