function prepend_value() {
        local varname=$1;
        local to_add=$2;
	eval value=\${$varname}
        if [[ $value = $to_add ]] ; then
                # $varname is identical to $to_add
        elif [[ -z $value ]] ; then
                # Is empty, setting $varname to $to_add
                eval export $varname=\$to_add
        elif [[ :$value: != *:$to_add:* ]] ; then
                # Have to add $to_add to $varname
                eval export $varname=\$to_add:\${$varname};
        else
                # $to_add is already in $value
        fi
}

function prepend_if_exists() {
	local varname=$1
	local dir=$2
	if [ -d $dir ] ; then
		prepend_value $varname $dir
	fi
}