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
bat - ECHO is off in the txt files
提问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 goal
variables remain uninitialised. When you are outputting them, the uninitialised variables evaluate to empty strings, and the corresponding echo
commands simply look like this:
您的某些goal
变量仍未初始化。当你输出它们时,未初始化的变量评估为空字符串,相应的echo
命令看起来像这样:
echo
Without parameters, echo
displays 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 echo
s and %goal…%
s. There's a number of delimiters you can use in that position, but, as follows from this answer, (
seems most appropriate:
为避免此行为并改为显示空字符串,请在echo
s 和s之间添加分隔符。您可以在该位置使用许多定界符,但是,如下来自此答案,似乎最合适:%goal…%
(
(
echo(%goal1%
echo(%goal2%
echo(%goal3%
echo(%goal4%
echo(%goal5%
) >> mcbingo.txt