本帖最后由 2198114498 于 2022-6-14 22:10 编辑
以下是我自己测试的代码,Test2和Test3均提示错误,
但我的需求是最外层不使用setlocal enabledelayedexpansion,所以不能用Test4。
有办法让endlocal&set %1=在for循环内成功吗?- @echo off
- cd /d %~dp0
-
- call :#Test t 11
- echo %t%
-
- call :#Test2 t 12
- echo %t%
-
- call :#Test3 t 13
- echo %t%
-
- setlocal enabledelayedexpansion
- call :#Test4 t 14
- echo %t%
-
- pause
- goto :eof
-
- :#Test
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in ("%2") do (
- set d2=%%a000
- goto :@1
- )
- goto :eof
- :@1
- endlocal &set /a %1=1%d2:~0,3%-1000
- goto :eof
-
- :#Test2
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in ("%2") do (
- set d2=%%a000
- endlocal &set /a %1=1%d2:~0,3%-1000
- goto :eof
- )
- goto :eof
-
- :#Test3
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in ("%2") do (
- set d2=%%a000
- endlocal &set /a %1=1!d2:~0,3!-1000
- goto :eof
- )
- goto :eof
-
- :#Test4
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in ("%2") do (
- endlocal &set d2=%%a000&set /a %1=1!d2:~0,3!-1000
- goto :eof
- )
- goto :eof
复制代码
|