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\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
I found that I can use $env:Path
within PowerShell to see my current system path. However, everything runs together on one line. Is there a way to pipe the output of $env:Path
to another command that will print each path value separately (i.e. printing on a new line for everything that is delimited by a semi-colon)?
Currently it prints something like this:
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;
I'd rather have something like this:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我有用。
Works for me.
在 Unix 上,您可以简单地完成此操作。
您可以使用以下任一方法在 Windows 上模拟此工作流程:
安装
gnu coreutils 并将 bin 目录添加到系统路径
或
将命令行工具的文件夹添加到系统路径。例如,“C:\Program Files (x86)\bin\”
下载 tr 作为 移植自的 powertools 的一部分UNIX。将它们提取到其他地方。 (例如,“C:\Program Files (x86)\bin\perl\”
将包含这些内容的名为 tr.bat 的 bat 文件添加到您的 bin 中。文件夹:
(路径应与提取 perl 工具的位置匹配)
结果
On Unix you can do this with simply
You can emulate this workflow on Windows with either of the following:
EITHER
Install gnu coreutils and add the bin directory to your system path
OR
Add a folder for your command line tools to your system path. E.g, "C:\Program Files (x86)\bin\"
Download tr as part of the powertools ported from unix. Extract them somewhere else. (E.g, "C:\Program Files (x86)\bin\perl\"
Add a bat file called tr.bat with these contents to your bin folder:
(Path should match where you extracted the perl tools)
Result