I am trying to search for a shell script if it is running and then assigning the count to a variable. Let the script be ScriptXYZ.sh. I wrote:
proc_count=$(/bin/ps -ef | grep ScriptXYZ.sh | grep -v grep | wc -l)
The problem that I am facing is that even when there is no instance of the ScriptXYZ.sh running I get a proc_count = 2. I tried running the command directly in the terminal and it yielded zero. But this variable always fetches value 2. I tried to put the quotes around it.
proc_count="$(/bin/ps -ef | grep ScriptXYZ.sh | grep -v grep | wc -l)"
But that also didn't change the value. Can anyone please explain why is this happening?