bat - ECHO 在 txt 文件中关闭

发布于 2024-12-05 22:04:00 字数 507 浏览 1 评论 0原文

: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖不如嘢 2024-12-12 22:04:00

您的一些目标变量仍未初始化。当您输出它们时,未初始化的变量计算为空字符串,相应的 echo 命令看起来像这样:

echo

如果没有参数,echo 显示回显批处理命令的状态控制台(当ON时,它们会显示,当OFF时,这在批处理中更常见,但它们不显示)。

要避免此行为并显示空字符串,请在 echo%goal...% 之间添加分隔符。您可以在该位置使用许多分隔符,但是,如下所示 这个答案(似乎最合适:

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

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:

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).

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:

(
echo(%goal1%
echo(%goal2%
echo(%goal3%
echo(%goal4%
echo(%goal5%
) >> mcbingo.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文