19 December 2015

Making smart use of bash and scripts written for bash can help you have more time for more important things than administering your system.

Path ordering is especially necessary when you are using many custom executables such as scripts so that the right ones will be called. Do you know how many different versions of Python or git are on your system?

In my .bash_profile I erase the path or rather start with a minimal path because running a terminal without a minimal path will result in an immediate exit. This would happen if I used unset PATH to clear the way.

A minimal path in OS X is

export PATH=/usr/bin:/bin:/usr/sbin:/sbin

I then use the following pathadd function to customize the order of the PATH by individually adding path items to the start of the path.

pathadd() {
    if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
        PATH="$1:$PATH" # Add to the front of the path.

As an example, to add /usr/local/bin to the path, you can use


blog comments powered by Disqus