Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo %path% on separate lines?

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\; 
like image 566
Carl R Avatar asked Feb 25 '11 08:02

Carl R


People also ask

How do I split a path in bash?

Just use path=${p%/*} and file=${p##*/} . Or use basename and dirname .

How do you echo the path?

To print the entire path, use echo %path% . This will print all directories on a single line separated with semicolons ( ; ) To search / replace a string in a variable, use %path:a=b% which will replace all a characters with b. echo. is used to print a newline.

How do I show the path in bash?

For Bash, you simply need to add the line from above, export PATH=$PATH:/place/with/the/file, to the appropriate file that will be read when your shell launches. There are a few different places where you could conceivably set the variable name: potentially in a file called ~/. bash_profile, ~/. bashrc, or ~/.

What does echo $PATH print?

echo $PATH doesn't create a variable, it prints the current contents of an already-existing variable.


2 Answers

Try:

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

or

$env:path.split(";") 
like image 159
Ekkehard.Horner Avatar answered Oct 13 '22 04:10

Ekkehard.Horner


Fewer keystrokes using either the split operator or method

$env:Path -split ';' $env:Path.split(';') 
like image 31
Doug Finke Avatar answered Oct 13 '22 05:10

Doug Finke