在单独的行上回显%path%?


83

使用Windows命令提示符,我可以回显%path%并在单独的行中获取生成的路径吗?类似于Windows的东西:

echo $path | tr ':' '\n'

我可以使用vanilla cmd进行此操作,还是需要Powershell或js脚本编写?

示例echo%path%输出:

C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;

所需的输出:

C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;
C:\Program Files\Microsoft SQL Server\90\Tools\binn\;
C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;

Answers:


140

尝试:

 ($env:Path).Replace(';',"`n")

要么

$env:path.split(";")

以下是什么问题?powershell -Command($ env:Path).Replace(';',“`n”)
Carl R

4
PowerShell具有-replace运算符:$env:Path -replace ';',"n“`
stej 2011年

5
包含分号的引用路径将失败。
乔伊,

@Joey:那我该怎么办呢?
埃里克

1
@stej使用三次反引号:$env:Path -replace ';',"`n"
wjandrea

44

使用split运算符方法减少了击键次数

$env:Path -split ';'
$env:Path.split(';')

3
包含分号的引用路径将失败。
乔伊,

5
看起来有点不错:($env:Path).Split(";") | Sort-Object
jrsconfitto 2012年

8

这对我有效(在cmd窗口中):

powershell -Command ($env:Path).split(';')
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.