为什么我在Makefile中使用pgrep
它找到一个进程ID但是在shell中运行时却没有?例如,假设我有这个makefile
SHELL = /bin/bash
tst:
if pgrep -f askdfkasdfj ; then \
kill $$(pgrep -f askdfkasdfj); \
fi
当我运行make tst
时,它找到一个进程并进入if
体,即使没有名为“askdfkasdfj”的进程。我试图用ps aux | grep ...
替换pgrep
,在这个例子中运行正常,并遇到了这个问题。
我认为它找到了来自makefile本身的命令。 make
正在执行类似的事情:
/bin/bash -c 'if pgrep -f askdfkasdfj ; then kill $$(pgrep -f askdfkasdfj); fi'
这包含askdfkasdfj
参数中的-c
,因此匹配。
但是我不确定为什么当你使用ps aux | grep
时这种情况也不会发生。