Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add paths to $PATH from multiple places in .bashrc/etc. : http://proccli.com/easy-add-paths-path-bash
# Push a path to our $PATH variable
# Usage:
# push_path <path> [after]
# If after is specified it will appear at the end of $PATH, otherwise it is unshifted
push_path(){
if ! echo $PATH | egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}
# Push all local/**/bin
push_path /usr/local/bin
for path in `ls -d /usr/local/*/bin 2>/dev/null`; do
push_path $path
done
# Push ~/bin
push_path $HOME/bin
# Push /opt/bin at the end
push_path /opt/bin "after"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.