|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『楼 主』:
什么情况下该使用变量延迟?
使用 LLM 解释/回答一下
请问在什么情况下应该使用变量延迟?
格式是什么样的?
变量延迟又有什么作用呢?
In what situations should variable delays be used? What is the format? What is the role of variable delays?
此帖被 -5 点积分 点击查看详情 评分人:【 everest79 】 | 分数: 0 | 时间:2007-3-26 10:39 | 评分人:【 pzr 】 | 分数: +1 | 时间:2007-8-31 14:43 | 评分人:【 ab200210 】 | 分数: +2 | 时间:2007-10-1 16:40 |
|
|
|
2006-5-21 12:30 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
   『第 2 楼』:
使用 LLM 解释/回答一下
───────────────── 版务记录 ─────────────────
执行:Will Sort
操作:移动主题:自《DOS疑難解答 & 問題討論 (解答室)》
说明:依照主题内容分类,更适合于发表在此版区
提示:原版区转向链接三日后将删除
处罚:扣除因发表该主题而奖励的6点积分,版区违规惩罚性扣除2点积分
───────────────── 版务记录 ─────────────────
Re namejm:
关于环境变量延迟扩展,使用set /?可以查看到部分说明,不过考虑到其粗劣的翻译水平,建议在查看之前,首先chcp 437切换为英文查看原英文说明。鉴于文中已说得十分详尽,而且有数个代码示例,应该不难理解。在此仅略作一些补充。
在许多可见的官方文档中,均将使用一对百分号闭合环境变量以完成对其值的替换行为称之为“扩展(expansion)”,这其实是一个第一方的概念,是从命令解释器的角度进行称谓的,而从我们使用者的角度来看,则可以将它看作是引用(Reference)、调用(Call)或者获取(Get)。
而命令解释器是扩展环境变量的行为大致如下:首先读取命令行的一条完整语句,在进行一些先期的预处理之后,命令被解释执行之前,会对其中用百分号闭合的字符串进行匹配,如果在环境空间中找到了与字符串相匹配的环境变量,则用其值替换掉原字符串及百分号本身,如果未得到匹配,则用一个空串替换,这个过程就是环境变量的“扩展”,它仍然属于命令行的预处理范畴。
而一条“完整的语句”,在NT的命令解释器CMD中被解释为“for if else”等含有语句块的语句和用“& | && ||”等连接起来的复合语句。
因此,当CMD读取for语句时,其后用一对圆扩号闭合的所有语句将一同读取,并完成必要的预处理工作,这其中就包括环境变量的扩展,所以在for中的所有语句执行之前,所有的环境变量都已经被替换为for之前所设定的值,从而成为一个字符串常量,而不再是变量。无论在for中将那些环境变量如何修改,真正受到影响的只是环境变量空间,而非for语句内部。
而为了能够在for语句内部感知环境变量的动态变化,CMD设计了延迟的环境变量扩展特性,也就是说,当CMD读取了一条完整的语句之后,它不会立即执行变量的扩展行为,而会在某个单条语句执行之前再进行扩展,也就是说,这个扩展行为被“延迟”了。
延迟环境变量扩展特性在CMD中缺省是关闭的,开启它的方法目前有两个:一是CMD /v:off(此处说法有误,应为 CMD /v:on——namejm 注),它会打开一个新的命令行外壳,在使用exit退出这个外壳之前,扩展特性始终有效,常用于命令行环境中;二是setlocal EnableDelayedExpansion,它会使环境变量的修改限制到局部空间中,在endlocal之后,扩展特性和之前对环境变量的修改将一同消失,常用于批处理语句中。
Last edited by namejm on 2007-3-17 at 09:01 PM ]
───────────────── Moderation Record ─────────────────
Performed by: Will Sort
Operation: Move Topic: From "DOS Troubleshooting & Question Discussion (Help Desk)"
Description: According to topic content classification, it is more suitable to be posted in this forum area
Tip: The original area redirect link will be deleted after three days
Punishment: Deduct 6 points of points awarded for posting this topic, and deduct 2 points of points for forum area violation penalty
───────────────── Moderation Record ─────────────────
Re namejm:
Regarding environment variable delayed expansion, you can check some instructions using set /?. However, considering its crude translation level, it is recommended to first switch to English by chcp 437 to view the original English instructions before checking. Since the text has been described very detailedly and there are several code examples, it should not be difficult to understand. Only some supplements are made here.
In many visible official documents, the behavior of using a pair of percent signs to close an environment variable to complete the replacement of its value is called "expansion" (expansion), which is actually a first-party concept, referred to from the perspective of the command interpreter. From our user's perspective, it can be regarded as reference (Reference), call (Call) or get (Get).
And the behavior of the command interpreter to expand environment variables is roughly as follows: First, read a complete statement of the command line. After some preliminary preprocessing, before the command is interpreted and executed, it will match the string closed with percent signs. If a matching environment variable is found in the environment space, its value will be used to replace the original string and the percent sign itself. If no match is obtained, an empty string will be used for replacement. This process is the "expansion" of the environment variable, which still belongs to the preprocessing category of the command line.
And a "complete statement" is interpreted in the NT command interpreter CMD as statements containing statement blocks such as "for if else" and compound statements connected by "& | && ||" and so on.
Therefore, when CMD reads a for statement, all statements closed with a pair of parentheses after it will be read together, and necessary preprocessing work will be completed, including the expansion of environment variables. Therefore, before all statements in the for are executed, all environment variables have been replaced with the values set before the for, thus becoming a string constant, and no longer a variable. No matter how those environment variables are modified in the for, what is really affected is the environment variable space, not the inside of the for statement.
And in order to be able to perceive the dynamic changes of environment variables inside the for statement, CMD has designed the delayed environment variable expansion feature, that is, when CMD reads a complete statement, it will not immediately perform the variable expansion behavior, but will expand again before a single statement is executed, that is, this expansion behavior is "delayed".
The delayed environment variable expansion feature is off by default in CMD. There are currently two methods to turn it on: one is CMD /v:off ( There is a mistake here, it should be CMD /v:on——note by namejm ), which will open a new command line shell. Before using exit to exit this shell, the expansion feature is always effective, which is often used in the command line environment; the second is setlocal EnableDelayedExpansion, which will limit the modification of environment variables to the local space. After endlocal, the expansion feature and the previous modifications to environment variables will disappear together, which is often used in batch processing statements.
Last edited by namejm on 2007-3-17 at 09:01 PM ]
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-5-22 14:08 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
   『第 3 楼』:
使用 LLM 解释/回答一下
谢谢willsort的详细解答.set /?的中文帮助看得似懂非懂,主要是里面有几个生涩的术语,看了willsort的解释之后,才明白"扩展"原来就是常用的引用、调用之类的动作,有种恍然大悟的感觉.
原来在《DOS疑難解答 & 問題討論 (解答室)》这个版块发帖求助习惯了,新版开张之后,一下子还没转过弯来,造成了发帖发错地方的错误,给版主的管理带来了麻烦,在此深表歉意.但是对"扣除标题违规惩罚性2点积分"这一条,我觉得挺冤枉,因为我的标题似乎没有引起歧义或者大而无边之类的错误,如果说我发错地方了要对我进行附加惩罚扣分,我没什么异议,但是"标题违规"这个说法似乎不妥当.个人意见,请版主指正.
Thanks to willsort for the detailed explanation. The Chinese help for `set /?` was a bit hard to understand. There were a few technical terms that were tough. After reading willsort's explanation, I realized that "expansion" is actually common actions like referencing and calling. It's like a light - bulb moment.
I was used to posting for help in the "DOS疑难解答 & 问题讨论(解答室)" section. After the new version was launched, I didn't adjust right away and made a mistake in posting to the wrong place, causing trouble for the moderators. I'm really sorry about that. But I feel a bit wronged about "deducting 2 points of punitive points for title violation". It seems my title didn't cause ambiguity or was too broad. If it's an additional punishment for posting in the wrong place, I have no objection, but the term "title violation" doesn't seem appropriate. This is just my personal opinion. I hope the moderators can give some advice.
|
|
2006-5-22 23:14 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Re namejm:
多谢细心指出版务记录中的笔误,现已做出修正,这个版本的版务记录模板已经使用了月余,第一次有人能指出其中的笔误;同时感于兄的诚恳,为此奖励3楼回复帖16点积分,同时提请批处理室其它版主扣除2楼的回复帖相应的16点积分,因为我无法对自己的回复进行评分。
Re namejm:
Thanks for carefully pointing out the typo in the moderation record. It has been corrected now. This version of the moderation record template has been in use for more than a month, and this is the first time someone has pointed out the typo. At the same time, moved by your sincerity, I will award 16 points of points to the reply on floor 3. At the same time, I ask other moderators in the Batch Processing Room to deduct 16 points of points from the reply on floor 2, because I can't rate my own reply.
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-5-23 00:23 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by willsort at 2006-5-23 00:23:
Re namejm:
多谢细心指出版务记录中的笔误,现已做出修正,这个版本的版务记录模板已经使用了月余,第一次有人能指出其中的笔误;同时感于兄的诚恳,为此奖励3楼回复帖16点积分,同时提请批处理室其它版主扣除2楼的回复帖相应的16点积分,因为我无法对自己的回复进行评分。
嘿嘿,以前发错了两个帖子,共扣除16分,现在又蒙版主法外施仁,又全部补回来了,高兴.既然是模板的原因,错不在版主,请求其他版主对willsort版主不做扣分操作,同时对willsort版主勇于自责的负责任的态度深表钦佩.
Hehe, I posted two wrong posts before, totaling 16 points deducted. Now I'm covered by the moderator's mercy and all are made up. Since it's the template's reason, it's not the moderator's fault. I request other moderators not to deduct points from willsort, and deeply admire willsort's responsible attitude of daring to blame oneself.
|
|
2006-5-23 00:34 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
两位都这么诚恳,小弟才深表钦佩``
Both of you are so sincere, so I really admire you, junior brother.
|
|
2006-9-22 23:43 |
|
|
jieok3375
中级用户
  
积分 282
发帖 130
注册 2006-9-20 来自 广东
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
好像有点明白了。
It seems to have a bit of understanding.
|

~~~~好好学习
天天向上~~~~ |
|
2006-10-19 04:57 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-10-19 08:41 |
|
|
hake
初级用户
 
积分 103
发帖 43
注册 2006-12-22
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
关于环境变量延迟扩展,使用set /?可以查看到部分说明,不过考虑到其粗劣的翻译水平,建议在查看之前,首先chcp 437切换为英文查看原英文说明。鉴于文中已说得十分详尽,而且有数个代码示例,应该不难理解。在此仅略作一些补充。
你们的中文能好点吗?
Regarding environment variable delayed expansion, you can view some instructions using set /?. However, considering its poor translation level, it is recommended to first switch to English by chcp 437 to view the original English instructions. Since the text has been very detailed and there are several code examples, it should not be difficult to understand. Here, only a few supplements are made.
Can your Chinese be better?
|
|
2006-12-29 06:13 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
请问楼上有什么疑惑?可以说出来大家帮你。
May I ask what doubts the person above has? You can say it out and everyone will help you.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-29 06:16 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
凡是要在for语句后,再次调用你
原先定义的变量
你就要用变量延迟
我终于搞定一个问题了
呵呵
Whenever you need to call the variables you originally defined again after the for statement, you need to use variable delay. I finally solved a problem. Hehe
|
|
2007-1-13 11:04 |
|
|
g4rr
初级用户
 
积分 68
发帖 32
注册 2007-1-24 来自 广东潮州
状态 离线
|
|
2007-1-28 15:59 |
|
|
gues1688
新手上路

积分 8
发帖 5
注册 2006-11-25
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
延迟为何物,总算是知道了
谢谢willsort!
What is delay, finally I know. Thanks willsort!
|
|
2007-1-29 02:43 |
|
|
hngaoshou
社区乞丐
gaoshou
积分 -16
发帖 77
注册 2007-1-30
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
???
++++++++++分
???
++++++++++Points
|

:cool:
[swf=1,1]http://img63.imageshack.us/my.php?image=58098766zh0.swf[/swf] |
|
2007-2-1 02:51 |
|
|
jmzsyt
新手上路

积分 10
发帖 5
注册 2006-11-21
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
顶下~太高科技看不懂
Bump up~ Too high-tech, can't understand
|
|
2007-3-2 02:28 |
|