windows bat - ECHO 在 txt 文件中关闭

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7475551/
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-15 18:07:01  来源:igfitidea点击:

bat - ECHO is off in the txt files

windowsbatch-fileecho

提问by david

:obje7
set gn=%random%
if /i %gn% lss 1 goto obje%go%
if /i %gn% gtr 5 goto obje%go%
set goal%gn%="test"
echo hi > goal%go%.txt
echo hi > g2.txt
goto go

that sets test in goal%random_number%, right?

在目标%random_number% 中设置测试,对吗?

(
echo %goal1%
echo %goal2%
echo %goal3%
echo %goal4%
echo %goal5%
) >> mcbingo.txt

and the result i get is:

我得到的结果是:

 ECHO is off.
 test
 ECHO is off.
 test
 test

and all the :objeX are the same code, but changed X and the g2.txt is g1.txt for example.

并且所有的 :objeX 都是相同的代码,但更改了 X 并且 g2.txt 是 g1.txt 例如。

anyone have any idea whats wrong?

任何人都知道什么是错的?

回答by Andriy M

Some of your goalvariables remain uninitialised. When you are outputting them, the uninitialised variables evaluate to empty strings, and the corresponding echocommands simply look like this:

您的某些goal变量仍未初始化。当你输出它们时,未初始化的变量评估为空字符串,相应的echo命令看起来像这样:

echo

Without parameters, echodisplays the status of echoing batch commands to the console (when ON, they are displayed, when OFF, which is more typical in batches, they aren't).

不带参数,echo将批处理命令的回显状态显示到控制台(当 时ON,显示它们,当 时OFF,在批处理中更典型,它们不显示)。

To avoid this behaviour and display empty strings instead, add delimiters between echos and %goal…%s. There's a number of delimiters you can use in that position, but, as follows from this answer, (seems most appropriate:

为避免此行为并改为显示空字符串,请在echos 和s之间添加分隔符。您可以在该位置使用许多定界符,但是,如下来自此答案,似乎最合适:%goal…%(

(
echo(%goal1%
echo(%goal2%
echo(%goal3%
echo(%goal4%
echo(%goal5%
) >> mcbingo.txt