#!/bin/bash # no bashisms so it can be used in debian profile run by dash # --start adds to start of path, which will give it highest priority # --ifexists will add to path only if the directory exists path_add() { local found x y z local ifexists start ifexists=false start=false while [ "$1" = --* ]; do if [ "$1" = --start ]; then start=true elif [ "$1" = --ifexists ]; then ifexists=true fi shift done for x in "$@"; do found=false IFS=: for y in $PATH; do [ "$x" = "$y" ] && found=true done unset IFS if ! $found; then if ! $ifexists || [ -d $x ]; then if [ ! "$PATH" ]; then PATH="$x" elif $start; then PATH="$x:$PATH" else PATH="$PATH:$x" fi fi fi done }