[bash] Verify substring in shell var

From: pt (mnemotronic_at_yahoo.com)
Date: 04/30/03


Date: 29 Apr 2003 21:23:18 -0700

I'm trying to verify that a shell variable (PATH) contains a directory
and, if not, add it to PATH. I've seen:

if ! echo $PATH | /bin/grep -q "/fred" ; then
    PATH=$PATH:/fred
fi

but it occurs to me I might be able to do something like this:

if [[ $PATH != */fred* ]]; then
    PATH=$PATH:/fred
fi

Is there any argument for either method (or any six other ways to do
the same thing)? Any reason to do it entirely "within" the shell vs.
via external executables (like "grep")?