Powershell script to print out each value in the system path
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 valu开发者_如何学编程e 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
$env:Path.split(";")
PS C:\Users\user> $env:Path.split(";")
C:\Program Files (x86)\Haskell\bin
C:\Program Files (x86)\Haskell Platform\2011.2.0.1\lib\extralibs\bin
C:\Program Files (x86)\Haskell Platform\2011.2.0.1\bin
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Windows\system32
...
Works for me.
On Unix you can do this with simply
echo $path | tr ";" "\n"
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:
@echo off
perl "C:\Program Files (x86)\bin\perl\tr" %*
(Path should match where you extracted the perl tools)
Result
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
...
精彩评论