Windows 用于打印系统路径中的每个值的Powershell脚本
我发现我可以在PowerShell中使用Windows 用于打印系统路径中的每个值的Powershell脚本,windows,scripting,powershell,Windows,Scripting,Powershell,我发现我可以在PowerShell中使用$env:Path查看我当前的系统路径。然而,一切都在一条线上运行。是否有办法将$env:Path的输出通过管道传输到另一个命令,该命令将分别打印每个路径值(即,在新行上打印分号分隔的所有内容) 目前它打印的内容如下: C:\Some Test Directory\With\Some\Files\In\It;C:\Some Test Directory\With\Some\Files\In\It;C:\Some Test Directory\With\So
$env:Path
查看我当前的系统路径。然而,一切都在一条线上运行。是否有办法将$env:Path
的输出通过管道传输到另一个命令,该命令将分别打印每个路径值(即,在新行上打印分号分隔的所有内容)
目前它打印的内容如下:
C:\Some Test Directory\With\Some\Files\In\It;C:\Some Test Directory\With\Some\Files\In\It;C:\Some Test Directory\With\Some\Files\In\It;C:\Some Test Directory\With\Some\Files\In\It;C:\Some Test Directory\With\Some\Files\In\It;
C:\Some Test Directory\With\Some\Files\In\It
C:\Some Test Directory\With\Some\Files\In\It
C:\Some Test Directory\With\Some\Files\In\It
C:\Some Test Directory\With\Some\Files\In\It
C:\Some Test Directory\With\Some\Files\In\It
我宁愿吃这样的东西:
C:\Some Test Directory\With\Some\Files\In\It;C:\Some Test Directory\With\Some\Files\In\It;C:\Some Test Directory\With\Some\Files\In\It;C:\Some Test Directory\With\Some\Files\In\It;C:\Some Test Directory\With\Some\Files\In\It;
C:\Some Test Directory\With\Some\Files\In\It
C:\Some Test Directory\With\Some\Files\In\It
C:\Some Test Directory\With\Some\Files\In\It
C:\Some Test Directory\With\Some\Files\In\It
C:\Some Test Directory\With\Some\Files\In\It
适合我。在Unix上,您只需使用
echo $path | tr ";" "\n"
您可以在Windows上使用以下任一选项模拟此工作流:
或者
安装bin目录并将其添加到系统路径
或
结果
C:\>echo %path% | tr ";" "\n"
C:\Program Files (x86)\bin\
C:\Perl\site\bin
C:\Perl\bin
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\Python27
...
虽然这会起作用,但对于您已经可以在PowerShell中轻松完成的事情来说,这是一种过火的做法。也许吧,但我向那些来自unix环境并且没有兴趣/动机学习PowerShell的人(比如我自己)提供这一点。对不起,这听起来有点屈尊。我的意思是,我现在可以通过“grep Windows”来实现这一点并获取路径中的所有Windows子目录。我不知道如何在Powershell中执行此操作。