Cmd windows 10 allow variables with spaces at the right

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Cmd windows 10 allow variables with spaces at the right

#1 Post by carlos » 26 Apr 2018 18:00

Hello. This is new for me.
On cmd.exe of windows 10 the variable names allow spaces:

Code: Select all

set var=a
set var =b
set var  =c

echo %var%
echo %var %
echo %var  %
it output:

Code: Select all

a
b
c

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Cmd windows 10 allow variables with spaces at the right

#2 Post by Squashman » 26 Apr 2018 18:30

It's not new. It has been this way for a while. I can't test on XP anymore but I am pretty sure it did it like that on XP as well. It certainly does it on Windows 7. I see people do that on StackOverFlow all the time. It is probably the 2nd biggest problem that newbies have with batch files next to delayed expansion.

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

Re: Cmd windows 10 allow variables with spaces at the right

#3 Post by carlos » 26 Apr 2018 18:41

Yes, I confirm it, is the same on windows xp. But today I write some code like that. I forget that feature. :D

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Cmd windows 10 allow variables with spaces at the right

#4 Post by Squashman » 26 Apr 2018 19:10

carlos wrote:
26 Apr 2018 18:41
Yes, I confirm it, is the same on windows xp. But today I write some code like that. I forget that feature. :D
But the even confusing part is you can do this:

Code: Select all

set /a numb = 1 +1
echo %numb%

Post Reply