遍历数组批处理脚本
Iterating over an array batch script
在按照教程在批处理脚本中迭代数组时,我没有得到相同的结果:
@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]!
)
当我 运行 这个命令时,我得到:
批处理space很重要,因为它是一个参数定界符
set topic[0] = comments
应该是
set topic[0]=comments
cmd 的一些奇怪之处在于变量可以以 space
结尾
set topic[0] = comments
echo %topic[0] %
comments
在按照教程在批处理脚本中迭代数组时,我没有得到相同的结果:
@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]!
)
当我 运行 这个命令时,我得到:
批处理space很重要,因为它是一个参数定界符
set topic[0] = comments
应该是
set topic[0]=comments
cmd 的一些奇怪之处在于变量可以以 space
结尾set topic[0] = comments
echo %topic[0] %
comments