Echo %path% on separate lines?

PowershellPathCmd

Powershell Problem Overview


Using the windows command prompt, can I echo %path% and get the resulting paths on separate rows? Something like this but for windows:

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

Can I do this with vanilla cmd or do I need powershell or js scripting?

Example echo %path% output:

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\;

Desired output:

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\;

Powershell Solutions


Solution 1 - Powershell

Try:

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

or

$env:path.split(";")

Solution 2 - Powershell

Fewer keystrokes using either the split operator or method

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

Solution 3 - Powershell

this works for me (in a cmd window):

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCarl RView Question on Stackoverflow
Solution 1 - PowershellEkkehard.HornerView Answer on Stackoverflow
Solution 2 - PowershellDoug FinkeView Answer on Stackoverflow
Solution 3 - Powershellleonardo4itView Answer on Stackoverflow