Why do I get "Echo is on" when I try to print a variable in batch mode

I am trying to issue simple batch file scripts:

echo %1 set var = %1 echo %var% 

When I run it in XP, it gives me the expected result, but when I run it in Vista or Windows 7, I get "Echo is On" when I try to print (echo).

Below is the output of the program:

 G:\2012>abc.bat 1 G:\2012>echo 1 1 G:\2012>set var = 1 G:\2012>echo ECHO is on. G:\2012> 
+7
source share
1 answer

Get rid of spaces in the expression set. There may and may not be spaces on either side of the equal sign (=)

 set var=%1 

BTW: I usually run all my batch files with @echo off and end them with @echo, so I can avoid mixing the code with the batch file output. It just makes your batch file more enjoyable and clean.

+13
source

All Articles