本帖最后由 plp626 于 2011-5-22 09:30 编辑
这个兼容特殊字符- @echo off
- call:perm "< & > plp |"
- pause
-
- :perm <"s1 s2 ...">
- setlocal enabledelayedexpansion&set "s= %~1"&for /f "tokens=*" %%a in ("%~1")do Set "ss=%%a"
- if "!s: =!" == "" (echo "%~2 ") else for %%b in ("!ss: =" "!")do call:perm "!s: %%~b=!" "%~2 %%~b"
- endlocal&goto:eof
复制代码 这个可精简为:- @echo off&setlocal enabledelayedexpansion
- call:perm "< & > plp |"
- pause
-
- :perm <"s1 s2 ...">
- setlocal&set "s= %~1"&for /f "tokens=*" %%a in ("%~1")do Set "ss=%%a"
- if "!s: =!" == "" (echo "%~2 ") else for %%b in ("!ss: =" "!")do call:perm "!s: %%~b=!" "%~2 %%~b"
复制代码 依据:
setlocal enabledelayedexpansion后,子过程会自动继承变量延迟开启,
call一个子过程,若setlcoal后,在结束该子过程时默认endlocal。。。 |