bat - ECHO 在 txt 文件中关闭
: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
在 goal%random_number% 中设置测试,对吧?
(
echo %goal1%
echo %goal2%
echo %goal3%
echo %goal4%
echo %goal5%
) >> mcbingo.txt
我得到的结果是:
ECHO is off.
test
ECHO is off.
test
test
并且所有 :objeX 都是相同的代码,但更改了 X 并且 g2.txt 是 g1.txt 例如。
有人知道出了什么问题吗?
: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?
(
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.
anyone have any idea whats wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的一些
目标
变量仍未初始化。当您输出它们时,未初始化的变量计算为空字符串,相应的 echo 命令看起来像这样:如果没有参数,echo 显示回显批处理命令的状态控制台(当
ON
时,它们会显示,当OFF
时,这在批处理中更常见,但它们不显示)。要避免此行为并显示空字符串,请在
echo
和%goal...%
之间添加分隔符。您可以在该位置使用许多分隔符,但是,如下所示 这个答案,(
似乎最合适:Some of your
goal
variables remain uninitialised. When you are outputting them, the uninitialised variables evaluate to empty strings, and the correspondingecho
commands simply look like this:Without parameters,
echo
displays the status of echoing batch commands to the console (whenON
, they are displayed, whenOFF
, which is more typical in batches, they aren't).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: