#!/bin/bash

pathadd() {
    if [ -d "$1" ] && ! echo $PATH | grep -E -q "(^|:)$1($|:)" ; then
        if [ "$2" = "after" ] ; then
            PATH="$PATH:${1%/}"
        else
            PATH="${1%/}:$PATH"
        fi
    fi
}

pathrm() {
    PATH="$(echo $PATH | sed -e "s;\(^\|:\)${1%/}\(:\|\$\);\1\2;g" -e 's;^:\|:$;;g' -e 's;::;:;g')"
}
Put these in any script you wish to alter the PATH environment and you can now do.

pathadd "/foo/bar"
pathadd "/baz/bat" after
export PATH
You're guaranteed not to add to the path if it's already there. If you now want to ensure /baz/bat is at the start.

pathrm "/baz/bat"
pathadd "/baz/bat"
export PATH