I'll start by saying that I think this problem is a little less innocent than it sounds.
What I need to do: check for a folder within the PATH environment variable. It could be at the start or somewhere after. I just need to verify that that folder is there.
Example of my problem - let's use
SCENARIO 1: folder is not at the beginning of PATH
# echo "$PATH" /sbin:/usr/sbin:/opt/gnome:/var/opt/gnome # echo "$PATH" | grep ":/opt/gnome" /sbin:/usr/sbin:/opt/gnome:/var/opt/gnome
Note that the grep needs to be specific enough so that it doesn't catch
/var/opt/gnome. Hence the colon.
SCENARIO 2: folder is at beginning of PATH.
# echo "$PATH" /opt/gnome:/sbin:/usr/sbin:/var/opt/gnome # echo "$PATH" | grep "^/opt/gnome" /opt/gnome:/sbin:/usr/sbin:/var/opt/gnome
This is my problem - I need to search for either a colon or a start-of-line with this folder. What I would like to do is one of these two bracket expressions:
# echo $PATH | grep "[^:]/opt/gnome" # echo $PATH | grep "[:^]/opt/gnome"
[: have their own meanings. Therefore, the two commands above do not work.
Is there a way I can grep for these two scenarios in one command?