- 帖子
- 885
- 积分
- 1470
- 技术
- 190
- 捐助
- 0
- 注册时间
- 2021-10-13
|
7楼
发表于 2024-8-23 14:03
| 只看该作者
本帖最后由 aloha20200628 于 2024-8-23 14:38 编辑
运行以下代码可见》4种实况说明 ‘延迟变量’ 开启前后的值变及其 ‘续命’ 的一个有效方法...- @echo off &setlocal
- echo,第一轮
- set/a "v1=1,v2=2,v3=3"
- echo, 未开延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- setlocal enabledelayedexpansion
- set "v1=11" &set "v2=12" &set "v3=13"
- echo, 开启延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- endlocal
- echo, 关闭延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- echo,第二轮(续命之道)
- set/a "v1=1,v2=2,v3=3"
- echo, 未开延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- setlocal enabledelayedexpansion
- set "v1=21" &set "v2=22" &set "v3=23"
- echo, 开启延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- endlocal & set "v1=%v1%" &set "v2=%v2%" &set "v3=%v3%"
- echo, 关闭延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- echo,第三轮(复合语块-if)
- set/a "v1=1,v2=2,v3=3"
- echo, 未开延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- if 1 equ 1 (
- setlocal enabledelayedexpansion
- set "v1=31" &set "v2=32" &set "v3=33"
- echo, 开启延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- endlocal & set "v1=%v1%" &set "v2=%v2%" &set "v3=%v3%"
- )
- echo, 关闭延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- echo,第四轮(复合语块-for)
- set/a "v1=1,v2=2,v3=3"
- echo, 未开延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- for /l %%n in (1,1,1) do (
- setlocal enabledelayedexpansion
- set "v1=41" &set "v2=42" &set "v3=43"
- echo, 开启延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- endlocal & set "v1=%v1%" &set "v2=%v2%" &set "v3=%v3%"
- )
- echo, 关闭延迟变量》v1=%v1%,v2=%v2%,v3=%v3%
- endlocal&pause&exit/b
复制代码
|
-
2
评分人数
-
|