本帖最后由 newswan 于 2024-8-26 09:55 编辑
最后选择这种方式
a.bat- @echo off
- setlocal
-
- set _var1_=111
- call b.bat
-
- echo :1
- set _
-
- for /f "usebackq tokens=1,* delims==" %%a in (`set __`) do (
- set _b%%a=%%b
- set %%a=
- )
-
- echo :2
- set _
-
- endlocal
-
- pause
- exit/b
复制代码 b.bat- @echo off
- setlocal enableDelayedExpansion
-
- set __var1__=value1
- set __var2__=value2
- set __var3__=value3
-
- for /f "delims=" %%a in ('set __') do (
- if defined _inLocal_ (endlocal)
- set %%a
- )
-
- exit/b
复制代码 个人习惯,变量用 "_" 开头,要输出的变量,用 "__" 开头 |