I'm trying to write a script which greps for a running process.
I'm trying to avoid the actual grep from coming back from the ps aux
output.
However I'm getting varying results if I use a dot or not:
ps aux | grep [s]elenium
doesn't return anything.
ps aux | grep [s]elenium.jar
returns the grep command:
beebee 36155 0.0 0.0 15940 956 pts/0 S+ 16:20 0:00 grep --color=auto selenium.jar
Why is that?
Best Answer
I guess you have a file named
selenium.jar
but no file calledselenium
in your current folder.If you run
the shell will try to replace
[s]elenium.jar
with matching files names from the current folder. If there is a file calledselenium.jar
that will match and[s]elenium.jar
will be replaced byselenium.jar
.The shell will then execute the command with the replaced value, i.e.
To avoid this quote the regex to protect it from the shell: