为什么我会收到“回声打开"的消息尝试批量打印变量时 [英] Why I am getting "Echo is on" when trying to print a variable in batch
问题描述
我试图执行一个简单的批处理文件脚本:
I tring to excute a simple batch file scripts :
echo %1
set var = %1
echo %var%
当我在XP中运行它时,它会给我预期的输出,但是当我在Vista或Windows 7中运行它时,在尝试打印(回显)值时却显示回显已打开".
When I am running it in XP, it is giving me expected output, but When I am running it in Vista or windows 7, I am getting "Echo is On" when trying to print (echo) value.
下面是程序的输出:
G:\2012>abc.bat 1
G:\2012>echo 1
1
G:\2012>set var = 1
G:\2012>echo
ECHO is on.
G:\2012>
推荐答案
摆脱设置表达式中的空格.等号(=)的两侧可以并且应该没有空格
Get rid of the spaces in your set expression. There can and should be no spaces on either side of the equal sign (=)
set var=%1
顺便说一句:我通常在关闭@echo的情况下开始所有批处理文件,并在打开@echo的情况下结束它们,因此可以避免将代码与批处理文件的输出混淆.它只是使您的批处理文件输出更好,更干净.
BTW: I usually start all my batch files with @echo off, and end them with @echo on too, so I can avoid mixing code with the output of the batch file. It just makes your batch file output a little nicer and cleaner.
这篇关于为什么我会收到“回声打开"的消息尝试批量打印变量时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!