0

我想在 %PATH% 环境变量中定义的单行上查看每个项目。我用过以下

for %A in ("%path:;=" "%") do @echo %A

它在一行中返回每个项目,但在它们周围加上双引号,如下所示。

"C:\Windows\System32"
"C:\Windows\system32\Wbem"
"C:\Windows\System32\WindowsPowerShell\v1.0\"

如何在没有双引号的情况下打印它们?我尝试在命令中使用单引号,但无法正确使用。(%PATH% 中的某些整体中的路径中有空格)

4

1 回答 1

3
ECHO %path:;=&ECHO(%

:) :)


Edit for expansion.

The syntax %var:string1=string2% replaces all string1 with string2 within var hence this command is resolved to

echo directory1&echo(directory2&echo(directory3...

at each ; which is the separator used between directorynames in %path%.

The echo( is a trick construct. There are many characters which are ignored to one extent or another DIRECTLY following echo. SPACE is the most common, but the command ECHO will show the ECHO state - ECHO is on/off. ECHO( however will show nothing (other than any characters following the ( ).

As it happens, my path ends with ; so if I was to use &echo to replace ; then the line would be resolved to ....echo dirlast&echo and produce the ECHO state as a last line. Using echo( neatly overcomes this problem.

于 2013-06-26T07:09:22.843 回答