[英]Windows cmd (batch) for loop
I'm having some problems with my for loop. 我的for循环遇到一些问题。 This is what I got now:
这就是我现在得到的:
@echo off
set installPrograms=CCleaner,Adobe Reader,Cute PDF Writer
for %%a in ("%installPrograms:,=" "%") do echo %%a
pause >nul
This outputs: 输出:
"CCleaner"
"Adobe Reader"
"Cute PDF Writer"
What I want this to output is: 我要输出的是:
CCleaner
Adobe Reader
Cute PDF Writer
So I'd like it to output those programs without the " " marks. 因此,我希望它输出没有“”标记的程序。 Seems the spaces in the program names is causing problems if I change the code to something like:
如果我将代码更改为以下内容,似乎程序名称中的空格会引起问题:
for %%a in (%installPrograms:,= %) do echo %%a
Output:
CCleaner
Adobe
Reader
Cute
PDF
Writer
How can I make this work? 我该如何进行这项工作? Thanks.
谢谢。
just replace echo %%a
with echo %%~a
. 只需将
echo %%a
替换为echo %%a
echo %%~a
。
The Tilde ( ~
) removes any surrounding quotes (if there are any). 波浪号(
~
)删除所有引号(如果有)。
Described in for /?
描述
for /?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.