http://www.perlmonks.org?node_id=359168

# path-manipulating shell functions function lspath { echo $PATH | tr ':' '\n' } function makepath { unset NEW_PATH while read PATHEL; do NEW_PATH="$NEW_PATH:$PATHEL" done echo ${NEW_PATH#:} } function uniqpath { PATH=`lspath | awk '{seen[$0]++; if (seen[$0]==1){print}}' | makep +ath` } function cleanpath { uniqpath PATH=`lspath | sed -e 's|\/$||' -ne '/./p' | makepath` } function addpath { PATH=$1:$PATH cleanpath } function appendpath { PATH=$PATH:$1 cleanpath } function delpath { PATH=`lspath | grep -v "^$1\$" | makepath` } function editpath { TEMP=`mktemp "/tmp/${FUNCNAME}.XXXXXX"` lspath > $TEMP ${EDITOR:-vi} $TEMP PATH=`makepath < $TEMP` rm -f $TEMP }