SETLOCAL 和 ENABLEDELAYEDEXPANSION 如何工作? [英] How do SETLOCAL and ENABLEDELAYEDEXPANSION work?

查看:30
本文介绍了SETLOCAL 和 ENABLEDELAYEDEXPANSION 如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在大多数脚本中,两者通常在同一行中:

I notice in most scripts, the two are usually in the same line as so:

SETLOCAL ENABLEDELAYEDEXPANSION

这两个实际上是单独的命令并且可以写在单独的行上吗?

Are the two in fact separate commands and can be written on separate lines?

如果将ENABLEDELAYEDEXPANSION设置在脚本的第一行并且直到脚本结束才禁用它,是否会对脚本产生不利影响?

Will setting ENABLEDELAYEDEXPANSION have an adverse effect on a script if it is set on the first lines of the script and not disabled until the end of the script?

推荐答案

ENABLEDELAYEDEXPANSION 是传递给 SETLOCAL 命令的参数(查看 setlocal/?)

ENABLEDELAYEDEXPANSION is a parameter passed to the SETLOCAL command (look at setlocal /?)

它的效果在脚本或ENDLOCAL的持续时间内有效:

Its effect lives for the duration of the script, or an ENDLOCAL:

当到达批处理脚本的末尾时,隐含的 ENDLOCAL 是为该批处理发出的任何未完成的 SETLOCAL 命令执行脚本.

When the end of a batch script is reached, an implied ENDLOCAL is executed for any outstanding SETLOCAL commands issued by that batch script.

特别是,这意味着如果您在脚本中使用 SETLOCAL ENABLEDELAYEDEXPANSION采取特殊措施.

In particular, this means that if you use SETLOCAL ENABLEDELAYEDEXPANSION in a script, any environment variable changes are lost at the end of it unless you take special measures.

这篇关于SETLOCAL 和 ENABLEDELAYEDEXPANSION 如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆