I have the same task as Print Windows %PATH% with every entry on new line
I have a task: print all entries of %PATH% variable on new line. For example:
C:\Program Files\
C:\Windows
C:\Windows\System32
and so on...
which is achievable by echo %path:;=&echo.% as explained here
And I want to assign it to a command alias using DOSKEY
But the following script is failing for me
DOSKEY list=echo %path:;=&echo.%
Which just prints all of the paths while I'm defining the DOSKEY, and after that, when I try to invoke list command, it just doesn't work.
As mentioned by @eryksun you'll need to escape special chars.
Update: And to prevent a premature expanding - will use delayed expansion.
An explanation of how this work: we can't use directly solution with
echo ^%path:;=^&echo.^%because it's stored in macros already expanded. To prevent this I've tried to use delayed expansion (the part withcmd /v:on /c). It seemed almost working but without splitting on new lines (adding&for some reason doesn't work with delayed expansion).Then I started to search a way to split
!path!and found a neat trick with replacing;to" "(double quoted space) ("!path:;=" "!"). This splitting was good enough for a plainfor(without/foption). The rest is obvious.