Board logo

标题: [其他] 批处理命令for循环建立变量如何显示? [打印本页]

作者: China_Angel    时间: 2014-4-20 14:05     标题: 批处理命令for循环建立变量如何显示?

  1. setlocal enabledelayedexpansion
  2. set num=0
  3. for /f "delims=;" %%i in (123.txt) do (
  4. set _!num!=%%i
  5. set /a num+=1
  6. echo !_num!
  7. )
复制代码
像这里的Echo该怎么写才能显示变量的内容?
如果只是echo !_num!的话cmd会显示“ECHO 处于关闭状态。”
作者: xxpinqz    时间: 2014-4-20 15:08

!_num!永远都是空值。
  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "delims=;" %%i in (123.txt) do (
  3.         set /a num+=1
  4.         set "_!num!=%%i"
  5.         for %%a in (!num!) do echo,!_%%a!
  6. )
  7. pause
复制代码

作者: cjiabing    时间: 2014-4-20 17:21

你设置了 num   、   _!num!    两个变量,但你从来没设置!_num!,你又如何   echo !_num!




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2