0

While following a tutorial for iterating over arrays in a batch script I didn't get the same result:

enter image description here

@echo off 
setlocal enabledelayedexpansion 
set topic[0] = comments 
set topic[1] = variables 
set topic[2] = Arrays 
set topic[3] = Decision making 
set topic[4] = Time and date 
set topic[5] = Operators 

for /l %%n in (0,1,5) do ( 
   echo !topic[%%n]! 
)

When I run this command I get:

enter image description here

4

1 回答 1

5

在批处理空间中很重要,因为它是一个参数分隔符

set topic[0] = comments

应该

set topic[0]=comments

cmd 的奇怪之处在于变量可以以空格结尾

set topic[0] = comments
echo %topic[0] %
 comments
于 2017-06-05T14:43:58.103 回答