Created
November 22, 2010 20:05
-
-
Save robhurring/710572 to your computer and use it in GitHub Desktop.
Add paths to $PATH from multiple places in .bashrc/etc. : http://proccli.com/easy-add-paths-path-bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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