windows 批处理 - 回声或变量不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3097044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:24:47 来源:igfitidea点击:
Batch - Echo or Variable Not Working
提问by Greg
I have this little batch script:
我有这个小批处理脚本:
SET @var = "GREG"
ECHO %@var%
PAUSE
When I run it, it prints:
当我运行它时,它会打印:
H:\Dynamics>SET @var = "GREG"
H:\Dynamics>ECHO
ECHO is on.
H:\Dynamics>PAUSE
Press any key to continue . . .
Why won't it print the contents of @var? How do I know if @var is even being set?
为什么不打印@var 的内容?我怎么知道@var 是否被设置?
回答by tcooc
Dont use spaces:
不要使用空格:
SET @var="GREG"
::instead of SET @var = "GREG"
ECHO %@var%
PAUSE
回答by Jonathan Stanton
Try the following (note that there should not be a space between the VAR
, =
, and GREG
).
请尝试以下操作(请注意VAR
,=
、 和之间不应有空格GREG
)。
SET VAR=GREG
ECHO %VAR%
PAUSE