odd behavior of pgrep in bash script
Where are you getting your version of pgrep from?

The version I have from MacPorts is coded such that if you do not supply a pattern it will match all processes even if you have qualifiers such as the -P option.

When I issue pgrep -P&lt;ppid&gt; I get a full list of processes.  If add a pattern as in pgrep -P&lt;ppid&gt; \. then it works as expected only providing processes with the given ppid.

As to the behavior difference, maybe you have a couple versions of pgrep on your machine and the jenkins jobs have a different PATH so are finding a different version?

From terminal window you can look for multiple versions with:

mdfind -name pgrep


I also suggest you compare the PATH variable used in the job vs. interactive.

To view which file the shell will use, you can use type -p pgrep and type -a pgrep will show all places in the PATH where pgrep can be found.