Checking if PATH contains $HOME/mydir and adding it if not (all in a script)
I would write
case ":$PATH:" in
*:$HOME/mydir:*) echo it is in the path;;
*) echo not there ;;
esac
I write ":$PATH:" to ensure that the pattern matches if the desired path is either first or last in your $PATH.
You can write a simple bash script to do something like this.
echo $PATH | grep -q "/your/search/path"
Then check if $? is not 0, meaning no match, and if so add the path
export PATH=$PATH:/your/search/path