|
pcl83
初级用户
 
积分 32
发帖 13
注册 2006-10-3
状态 离线
|
『楼 主』:
for循环为什么只显示echo的状态?
使用 LLM 解释/回答一下
请看以下代码(批处理文件中):
-------------------------------------------
@echo off
FOR /L %%i in (1,1,3) do (
set /a T=%%
echo %T%)
pause>nul
--------------------------------------------
程序运行之后并没有我们预测的那样出现
1
2
3
而是:
ECHO 处于关闭状态。
........
究竟怎么回事,有什么解决办法?
──────────────── 版务记录 ────────────────
执行:namejm
原标题:高手速来帮忙
现标题:for循环为什么只显示echo的状态?
说明:因原标题过于模糊,不便于论坛的搜索和管理,在版主提示发表三日
之后,楼主尚未更改标题,现由本人代无奈何版主强制修改标题,并
扣除楼主4点积分(因为论坛积分规则有变,酌情减轻了处罚)。
──────────────── 版务记录 ────────────────
Last edited by namejm on 2006-10-19 at 01:09 ]
Please see the following code (in a batch file):
-------------------------------------------
@echo off
FOR /L %%i in (1,1,3) do (
set /a T=%%
echo %T%)
pause>nul
--------------------------------------------
After the program runs, it does not appear as we predicted:
1
2
3
Instead:
ECHO is off.
........
What's going on and what's the solution?
──────────────── Moderation Record ────────────────
Performed by: namejm
Original title: Expert, come quickly for help
Current title: Why does the for loop only display the echo status?
Explanation: The original title was too vague, which was not conducive to forum search and management. After the moderator's prompt was issued three days ago, the original poster had not changed the title. Now I, on behalf of the helpless moderator, forcibly modified the title and deducted 4 points from the original poster (because the forum points rules have changed, and the punishment has been reduced appropriately).
──────────────── Moderation Record ────────────────
Last edited by namejm on 2006-10-19 at 01:09 ]
|
|
2006-10-3 09:44 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
这是变量延迟的问题, 另外发现楼主的代码写错了, set /a T=%%
代码修改如下:
@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,3) do (
set T=%%i
echo !T!
)
pause>nul
This is a problem of variable delay. In addition, it is found that the code of the original poster is wrong, set /a T=%%. The code modification is as follows:
@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,3) do (
set T=%%i
echo !T!
)
pause>nul
|
|
2006-10-3 09:47 |
|
|
pcl83
初级用户
 
积分 32
发帖 13
注册 2006-10-3
状态 离线
|
|
2006-10-3 09:53 |
|
|
KIKOOOO
初级用户
 
积分 34
发帖 12
注册 2006-9-25
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
这里为什么要用!T!
不能用%T% ?
Why use!T! here instead of %T%?
|
|
2006-10-3 10:01 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
这牵涉到环境变量延迟的问题, 像这样的复合语句, cmd会对语句中的变量进行预处理. 这样for语句中的%T%就会被替换. 而%T%这个变量在for之前没有定义, 所以echo %T%显示echo 处于关闭状态.
开启延缓的环境变量, 就是不让cmd对复合语句中的环境变量进行预先处理. 从而使T这个变量能够正常地显示. 因为开启了环境变量, 所以要把 % 改成 ! ...
This involves the issue of environment variable delay. For a compound statement like this, cmd will preprocess the variables in the statement. Thus, %T% in the for statement will be replaced. And the variable %T% is not defined before the for, so echo %T% shows that echo is in a closed state.
To enable delayed environment variables is to prevent cmd from preprocessing environment variables in compound statements. Thus, the variable T can be displayed normally. Because environment variables are enabled, so change % to !...
|
|
2006-10-3 10:14 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃▓ 中国DOS联盟 >> 批处理室版务管理 _ □ ×┃
┠──────────────────────────────┬┨
┃Microsoft Windows XP │┃
┃(C) 版权所有 1985-2001 Microsoft Corp. │┃
┃ │┃
┃C:\无奈何>版务管理.cmd │┃
┃ │┃
┃ 版主提示 │┃
┃为了便于论坛用户浏览和版主管理,请您修改本主题的标题,以简要│┃
┃叙述主题的内容或意图如果您确认标题不需要修改,请继续回复该主│┃
┃题进行申辩,若申辩理由充分,将取消该通知如果您确认标题需要修│┃
┃改,请点击该主题首帖下方"编辑"按钮,在编辑页面中修改标题栏│┃
┃如果此通知发出三日后您仍未进行申诉或修改,将由版主进行修改,│┃
┃并对作者进行相应处罚处罚为扣除8点积分,包括追回您因发表主题│┃
┃奖励的6分和因标题违规而惩罚性扣除的2分在得知您做出积极恰当│┃
┃的回应后,版主将在三个工作日内删除本提示以消除对您的不利影响│┃
┃ │┃
┃C:\无奈何>▂ │┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷┛
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃▓ China DOS Union >> Batch Processing Room Moderation Management _ □ ×┃
┠──────────────────────────────┬┨
┃Microsoft Windows XP │┃
┃(C) Copyright 1985-2001 Microsoft Corp. │┃
┃ │┃
┃C:\NaiWaiHe>Moderation Management.cmd │┃
┃ │┃
┃ Moderator's Notice │┃
┃To facilitate forum users' browsing and moderators' management, please modify the title of this topic to briefly describe the content or intention of the topic. If you confirm that the title does not need to be modified, please continue to reply to this topic for defense. If the defense reason is sufficient, this notice will be canceled. If you confirm that the title needs to be modified, please click the "Edit" button below the first post of this topic, and modify the title bar in the editing page. If you still do not appeal or modify within three days after this notice is issued, the moderator will modify it and impose a corresponding penalty on the author. The penalty is to deduct 8 points, including 6 points recovered from the rewards you received for publishing the topic and 2 points deducted punitively for the title violation. After knowing that you have made a positive and appropriate response, the moderator will delete this notice within three working days to eliminate the adverse impact on you.│┃
┃ │┃
┃C:\NaiWaiHe>▂ │┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷┛
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-10-3 10:51 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
下面是不用!T!的!
@echo off
FOR /L %%i in (1,1,3) do set a=%%i&call :1
pause>nul
goto :eof
:1
echo %a%
Last edited by qwe1234567 on 2006-10-3 at 22:05 ]
Here'stown共同成意义是什么说的是什么意义都公共意义});!T!的成意义是什么说的是什么意义都公共意义});!T!的
```
@echo off
FOR /L %%i in (1,1,3) do set a=%%i&call :1
pause>nul
goto :eof
:1
echo %a%
```
Last edited by qwe1234567 on 2006-10-3 at 22:05 ]
Wait, there seems to be some confusion in the input. Let's focus on the code part. The code you provided is a batch script. Here's the translation of the code part as is:
```
@echo off
FOR /L %%i in (1,1,3) do set a=%%i&call :1
pause>nul
goto :eof
:1
echo %a%
```
And the rest of the text that doesn't seem to be related to the code is a bit jumbled. But based on the requirements, we mainly handle the code part. So the translated content for the code part remains as above, and the other jumbled text is just as it is presented here. But actually, the correct way is to just output the relevant parts properly. Let's correct and present clearly:
The batch code part translated is:
```
@echo off
FOR /L %%i in (1,1,3) do set a=%%i&call :1
pause>nul
goto :eof
:1
echo %a%
```
And the edit information part remains as:
Last edited by qwe1234567 on 2006-10-3 at 22:05 ]
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-10-3 21:58 |
|
|