Over the weekend I wrote what can only be described as a completely
over-engineered solution to something that was really nothing more than a minor
annoyance to me. I noticed that some paths in my
$PATH environmental variable were
duplicated, and some were there that didn’t exist on the filesystem, and over
all it was just a bit of a mess.
I remember encountering the
pathmunge bash function a couple years ago but I
didn’t want something that relied on
grep or any external commands - I wanted
to be able to manage
$MANPATH) with pure bash.
Functions to modify colon separated variables like
All of the logic is in a single file and can be sourced or copied directly into
bashrc file to be used. I pulled in
bash-path to my dotfiles with this
Given the following environment:
$ . path.bash $ PATH='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
You can add to
path_add (similar to
$ path_add /my/new/bin $ path_add /my/new/sbin before $ echo "$PATH" /my/new/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/my/new/bin