[Solved]leading digit, yet name ends in char [_,.] problem !

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

[Solved]leading digit, yet name ends in char [_,.] problem !

#1 Post by Ed Dyreen » 30 Oct 2011 22:33

Code: Select all

@echo off &Setlocal DisableDelayedExpansion

set "echo_=<nul set /p ="
%echo_%This
echo.



set "2echo_=>&2 %echo_%"
%2echo_%This
echo. &pause &exit

This
echo_This wordt niet herkend als een interne
of externe opdracht, programma of batchbestand.

Druk op een toets om door te gaan. . .



set "_2echo=>&2 %echo_%"
%_2echo%This
echo. &pause &exit

This
This
Druk op een toets om door te gaan. . .



set "2echo=>&2 %echo_%"
%2echo%This
echo. &pause &exit

This
This
Druk op een toets om door te gaan. . .
CMD BUG :!: :?:

This won't work !

Code: Select all

set "21echo_=<nul >con set /p ="
This works !

Code: Select all

set "@21echo_=<nul >con set /p ="
Last edited by Ed Dyreen on 01 Nov 2011 17:22, edited 11 times in total.

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

Re: XP CMD BUG when variable name ends with _underscore !

#2 Post by dbenham » 30 Oct 2011 22:58

That is odd - It doesn't look like expected behavior to me. :?

It works as expected on my Vista machine.


Dave Benham

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

Re: XP CMD BUG when variable name ends with _underscore !

#3 Post by Ed Dyreen » 30 Oct 2011 23:01

'
Yes, odd but it's real, tested in both VM and physicall pc running XP 32...

It only seems to affect echo commands.
At first I thought echo_ was interpreted as echo. and that that was the reason it failed,
but then i tested with 2necho_ and @2necho_ which led me too conclude this is another weird XP bug. :cry: :evil:

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

Re: XP CMD BUG when variable name ends with _underscore !

#4 Post by dbenham » 30 Oct 2011 23:14

You edited your post while I was preparing my 1st post. :roll:

To clarify - I do not see the behavior below on Vista

Code: Select all

set "echo_=<nul set /p ="
%echo_%This
echo.
I get the expected This

Code: Select all

%21echo_%This
This works for me on the command line in Vista, but fails in batch :?


Dave Benham

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

Re: XP CMD variable name ends with _underscore BUG !

#5 Post by Ed Dyreen » 30 Oct 2011 23:19

'
So it's not just an XP bug, :roll:

try this one, it's even weirder, same result:

Code: Select all

set "@21echo_=<nul >con set /p ="

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

Re: XP, Vista BUG variable name ends with _underscore !

#6 Post by dbenham » 30 Oct 2011 23:36

Ignore this post, I had a temporary loss of mind
Well not the same result, but still not correct.

Again, that works from command line, but not in batch.

From within batch:

Code: Select all

%21echo_%This
yields

Code: Select all

'1echo_This' is not recognized as an internal or external command,
operable program or batch file.


Code: Select all

%@21echo_%This
yields

Code: Select all

ThisC:\Users\Public\utils>


:!: :!: :!: :!: :!: :!: :!: :!:
Stop the presses - I'm not getting consistent behavior :!: :?:
Sometimes %@21echo_%This works from batch

Another #@% intermittent bug - but now its not just XP :evil: :evil: :evil:
Last edited by dbenham on 31 Oct 2011 06:26, edited 1 time in total.

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

Re: XP, Vista BUG variable name ends with _underscore !

#7 Post by dbenham » 30 Oct 2011 23:48

False alarm.

I forgot SET /P does not print newline.

So %@21echo_%This is giving correct result in Vista in batch and on command line.

I fooled myself as far as changing behavior - I had modified the code slightly.

Whew!

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

Re: XP, Vista BUG variable name ends with _underscore, .DOT

#8 Post by Ed Dyreen » 30 Oct 2011 23:51

'
WhoeHaa :shock: The .DOT is affected as well :!: :o

I could have guessed it, AND the DELIMS , as well...

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

Re: XP, Vista BUG No leading char, yet name ends in char [_,

#9 Post by dbenham » 31 Oct 2011 06:18

:? I don't understand - show some examples please.

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

Re: XP, Vista BUG No leading char, yet name ends in char [_,

#10 Post by alan_b » 31 Oct 2011 09:55

I am guessing that English is not the native language for
echo_This wordt niet herkend als een interne
of externe opdracht, programma of batchbestand.

Is it possible that Windows might alter its behaviour when installed for a foreign (to me) language ?

aGerman
Expert
Posts: 4705
Joined: 22 Jan 2010 18:01
Location: Germany

Re: XP, Vista BUG No leading char, yet name ends in char [_,

#11 Post by aGerman » 31 Oct 2011 12:42

You should avoid leading numbers in variable names. The reason why is simple:
%2echo_%
Is %2 an argument or is it part of a variable?

You could try the same with delayed expansion. Then you (and also cmd) are not that confused.
!2echo_!

Regards
aGerman

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

Re: XP, Vista BUG No leading char, yet name ends in char [_,

#12 Post by Ed Dyreen » 31 Oct 2011 18:38

'
aGerman wrote:You should avoid leading numbers in variable names. The reason why is simple:
%2echo_%
Is %2 an argument or is it part of a variable?
Your conclusion is not correct, it doesn't explain, next behavior on XP:

Code: Select all

@echo off

set "2echo_=>&2 <nul set /p ="
%2echo_% Hello
pause

set "2echo=>&2 <nul set /p ="
%2echo% Hello
pause
As you can see it's the combination of both a leading digit and an ending "special" character that is causing it !

Code: Select all

echo_ wordt niet herkend als een interne
of externe opdracht, programma of batchbestand.
Druk op een toets om door te gaan. . .
Hello
Druk op een toets om door te gaan. . .
DOS tells me, it can't decide whether it is part of a variable because of the underscore at the end.
Remove the ending underscore, and DOS will accept it as a variable so

%2echo_% -> %2 is it a variable ???
%2echo% -> %2 it is a variable.

Tested these to be sure DOS does not interpret %2echo_% as %2 and echo_

%2@echo_% -> %2 is it a variable ???
%2@echo% -> %2 it is a variable.
%2YOecho_% -> %2 is it a variable ???
%2YOecho% -> %2 it is a variable.

Do we have a bug, or can it still be explained :?:
Last edited by Ed Dyreen on 31 Oct 2011 19:31, edited 2 times in total.

aGerman
Expert
Posts: 4705
Joined: 22 Jan 2010 18:01
Location: Germany

Re: XP BUG leading digit, yet name ends in char [_,.] !

#13 Post by aGerman » 31 Oct 2011 19:29

Well Ed, the cmd on XP has a different behaviour. We all know that. But the main reason why it fails is the ambiguous %2. Perhaps it's an XP bug. However, M$ changed the bahaviour and now a variable with a leading number seems to be always parsed as an argument + string.
Because I never tested that much on XP I never used a combination with leading numbers. It's obvious that it would probably fail, isn't it.

Regards
aGerman

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

Re: XP, Vista BUG No leading char, yet name ends in char [_,

#14 Post by dbenham » 31 Oct 2011 20:20

@aGerman - thank you - your explanation makes perfect sense. :D

Ed Dyreen wrote:'
aGerman wrote:You should avoid leading numbers in variable names. The reason why is simple:
%2echo_%
Is %2 an argument or is it part of a variable?
Your conclusion is not correct, it doesn't explain, next behavior on XP:

Code: Select all

@echo off

set "2echo_=>&2 <nul set /p ="
%2echo_% Hello
pause

set "2echo=>&2 <nul set /p ="
%2echo% Hello
pause
As you can see it's the combination of both a leading digit and an ending "special" character that is causing it !

Code: Select all

echo_ wordt niet herkend als een interne
of externe opdracht, programma of batchbestand.
Druk op een toets om door te gaan. . .
Hello
Druk op een toets om door te gaan. . .
DOS tells me, it can't decide whether it is part of a variable because of the underscore at the end.
Remove the ending underscore, and DOS will accept it as a variable...

Ed - I'm not getting the same results as you. :?
All macro variants that begin with a number fail for me on both Vista and XP within a batch, even if there is no underscore on the end. All variants that do not begin with a number succeed. This is the behavior I expect with aGerman's explanation.

If I run the macros from the command line, then all variants work, again backing up aGerman's explanation since the command line does not attempt batch argument expansion.

The failures you are getting only occur in batch, correct :?:
You can run your batch with 2 arguments passed in and you should see the 2nd argument as part of your error message for the %2echo_% case.

The big mystery is why the %2echo% variant works in batch mode for you. :? You did test it in batch mode, yes :?:

Have you loaded and/or executed any of your macros prior to testing :?:
I'm thinking of the macros that exhibit the nasty XP FOR /F bug. I know that you are suppressing and/or ignoring the FOR /F error messages. I'm worried that if you run such macros and then run your ECHO macro tests, your machine might be in an unstable state. Try running the ECHO macro test with minimal code in a virgin CMD window.


Dave Benham

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

Re: XP BUG leading digit, yet name ends in char [_,.] !

#15 Post by Ed Dyreen » 31 Oct 2011 20:56

'
Dave, that is exactly what I tried.

I am running Service Pack 2 here, the VM runs service pack 1, both give me same results.
maybe it's service pack related.

If so, that would become a problem when my unattended scripts attempts updating to SP3 :( :cry:

All the tests were done using a "blank" batch file, I did not call it, just a mouseclick ...

I will try different systems,... ...

Post Reply