[DOS]Delayed environment variable expansion
来源:互联网 发布:linux怎么输入命令 编辑:程序博客网 时间:2024/05/17 03:05
Delayed environment variable expansion is useful for getting around
the limitations of the current expansion which happens when a line
of text is read, not when it is executed. The following example
demonstrates the problem with immediate variable expansion:
set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "%VAR%" == "after" @echo If you see this, it worked
)
would never display the message, since the %VAR% in BOTH IF statements
is substituted when the first IF statement is read, since it logically
includes the body of the IF, which is a compound statement. So the
IF inside the compound statement is really comparing "before" with
"after" which will never be equal. Similarly, the following example
will not work as expected:
set LIST=
for %i in (*) do set LIST=%LIST% %i
echo %LIST%
in that it will NOT build up a list of files in the current directory,
but instead will just set the LIST variable to the last file found.
Again, this is because the %LIST% is expanded just once when the
FOR statement is read, and at that time the LIST variable is empty.
So the actual FOR loop we are executing is:
for %i in (*) do set LIST= %i
which just keeps setting LIST to the last file found.
Delayed environment variable expansion allows you to use a different
character (the exclamation mark) to expand environment variables at
execution time. If delayed variable expansion is enabled, the above
examples could be written as follows to work as intended:
set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "!VAR!" == "after" @echo If you see this, it worked
)
set LIST=
for %i in (*) do set LIST=!LIST! %i
echo %LIST%
- [DOS]Delayed environment variable expansion
- Variable expansion Modifiers (parameter expansion)
- Environment variable
- Configure the environment variable
- My shell environment variable
- The CATALINA_HOME environment variable
- The http_proxy Environment Variable
- reading environment variable python
- Oracle:environment variable "PATH"
- PYTHONPATH environment variable
- Request.ServerVariables (server environment variable)
- linux java environment variable configure
- Environment variable ORACLE_UNQNAME not defined
- how to java --->environment variable
- Define environment variable in LINUX
- DISPLAY environment variable not set!
- environment variable 'STAGING_DIR' not defined
- Configure Java environment variable in debian 5.0
- OO编程思想之一---对象生命周期与内存模型
- 团队管理的一些观点。
- oracle包和REF CURSOR
- 快速删除ORACLE重复记录
- asp.net js css 等开发中可能会用到的- 不断更新
- [DOS]Delayed environment variable expansion
- extmail不能发邮件
- sql之left join、right join、inner join的区别
- .Net线程足迹(一)
- 防止页面刷新时表单的重复提交的最简单方法(C#)
- MFC DLL向导
- 情书一封
- 通过物化视图方式同步两服务器中数据表的两种不同方式的比较
- syslogd、logrotate和cronolog