pgrep 在 makefile 中返回 true,但在 shell 中不返回



为什么当我在 Makefile 中使用 pgrep 时它会找到一个进程 ID,但在 shell 中运行时却找不到?例如,假设我有此生成文件

SHELL = /bin/bash
tst:
    if pgrep -f askdfkasdfj ; then     
      kill $$(pgrep -f askdfkasdfj);   
    fi

当我运行make tst时,它会找到一个进程并进入if体,即使没有名为"askdfkasdfj"的进程。我试图用pgrep替换在这种情况下工作正常的ps aux | grep ...并遇到了这个问题。

我认为它找到了来自makefile本身的命令。 make正在执行类似的东西:

/bin/bash -c 'if pgrep -f askdfkasdfj ; then kill $$(pgrep -f askdfkasdfj); fi'

这在 -c 参数中包含askdfkasdfj,因此它匹配。

但我不确定为什么当你使用ps aux | grep时没有发生这种情况.

相关内容

最新更新