为什么当我在 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
时没有发生这种情况.