Simple tool to clean up PATH like strings by removing redundant and incorrect entries but keeping the relative order of the paths that remain.
$ export FAKEPATH=/usr/bin:/usr/local/bin:/usr/bin:/usr/sbin:.
$ export FAKEPATH=$(cleanpath $FAKEPATH)
$ echo $FAKEPATH
/usr/bin:/usr/local/bin:/usr/sbin
See this .bashrc for a real life example of usage.
- Redundant paths removed, but relative order of first occurence is maintained.
- Relative (unsafe) paths removed.
- The separator char defaults to
:
for posix paths, but can be specified as;
for windows paths.
usage: cleanpath [-h] [-separator <sep>] [<pathvar> [<pathvar> ...]]
Clean PATH like strings
positional arguments:
<pathvar> PATH values
optional arguments:
-h, --help show this help message and exit
-separator <sep> path separator char
Run unit tests with python -m unittest