DEV Community

Evgeny Pogrebnyak
Evgeny Pogrebnyak

Posted on

Quickly inspect or sanitize PATH variable on both Windows and Linux

I think this quote about PATH environment variable is quite right:

I always get the feeling that nobody knows what a PATH is and at this point they are too afraid to ask.

PATH environment variable syntax on Windows and Linux is different, so I wrote my own utility justpath to be able to explore PATH more easily.

I did start with one line commands that show directories line by line:

echo $PATH | tr ":" "\n"
Enter fullscreen mode Exit fullscreen mode
$env:PATH.split(";")
Enter fullscreen mode Exit fullscreen mode

But what if I wanted to make a list of duplicate directories or show paths that are not valid - not too easy to make a one-liner for this behavior and this is where a Python script comes handy. After install I can do:

justpath --invalid
justpath --duplicates
Enter fullscreen mode Exit fullscreen mode

More options and documentation here at project repo.
justpath can purge invalid or duplicate paths
and make a new PATH string that you can use at your
shell startup.

Top comments (0)