Possible Duplicate:
keep duplicates out of $PATH on source
Some of my scripts are located in $HOME/mydir. Unfortunately, they are not accessible from elsewhere if this dir is not part of PATH.
I would like to create a small scripts checking whether $HOME/mydir is part of PATH. If it is not, PATH should be updated with it and EXPORTED.
My question is: which command can I use to check whether $HOME/mydir is part of PATH? Thanks.
SOLUTION
For the records, I implemented the following:
echo "Before: $PATH"
echo $PATH | grep -q "$HOME/scripts"
if [ $? -eq 0 ]; then
PATH=$PATH:$HOME/scripts
export PATH
else
export PATH
fi
echo ""
echo "After: $PATH"
$0 == 0to$? -eq 0. You should try it with a some path that is not in your PATH – Rado Feb 18 '12 at 18:33