本帖最后由 zm900612 于 2011-4-25 22:27 编辑
在for中读取变量的办法有n种:- @echo off&setlocal enabledelayedexpansion
- for /f %%a in (a.txt) do (
- Set "Var=%%a"
- Echo !Var!
- pause
复制代码
- @echo off
- for /f %%a in (a.txt) do (
- Set "Var=%%a"
- Call Echo %%Var%%
- pause
复制代码
- @echo off
- for /f %%a in (a.txt) do (
- Set "Var=%%a"
- cmd /v:on Echo !Var!
- pause
复制代码
- @echo off
- for /f %%a in (a.txt) do (
- Set "Var=%%a"
- cmd /c Echo %%Var%%
- pause
复制代码
- @echo off
- for /f %%a in (a.txt) do (
- Set "Var=%%a"
- for /f "tokens=1* delims==" %%b in ('set Var') do echo %%c
- pause
复制代码 如果只需要显示,不需要做别的工作,那能不定义变量就尽量别定义:复制代码 复制代码 复制代码 复制代码 复制代码 复制代码 - @echo off
- for /f %%a in (a.txt) do echo %%a
- pause
复制代码 甚至fc都可以考虑 |