我正在处理批处理脚本,该脚本假定提示用户输入项目列表,然后依次处理每个项目。我的想法是,这可以通过for循环完成,但它不起作用。出于某种原因,它将用户输入的整个字符串(CanalyzerIF CanoeIF CometIF
)视为单个标记。
echo Enter the names of the projects, deliniating each with a space:
set /P PROJECT_LIST=
echo.
echo DEBUG: PROJECT_LIST is %PROJECT_LIST%
echo These are the projects you specified:
for /F "tokens=*" %%i in ("%PROJECT_LIST%") do (
echo %%i
)
我的脚本输出如下所示......
DEBUG: PROJECT_LIST is CanalyzerIF CanoeIF CometIF
These are the projects you specified:
CanalyzerIF CanoeIF CometIF
......当我期望/想要看到的是这样的时候:
DEBUG: PROJECT_LIST is CanalyzerIF CanoeIF CometIF
These are the projects you specified:
CanalyzerIF
CanoeIF
CometIF
如果我使用百分号(%
)或感叹号(!
)来包裹PROJECT_LIST
,那似乎并不重要。任何人都知道如何解决这个问题?
答案 0 :(得分:1)
尝试使用(普通FOR
可以用于itration):
echo Enter the names of the projects, deliniating each with a space:
set /P "PROJECT_LIST="
echo.
echo DEBUG: PROJECT_LIST is %PROJECT_LIST%
echo These are the projects you specified:
for %%i in (%PROJECT_LIST%) do (
echo %%i
)