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

问题描述 投票:0回答:1

为什么我在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,在这个例子中运行正常,并遇到了这个问题。

bash makefile process grep
1个回答
1
投票

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

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

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

但是我不确定为什么当你使用ps aux | grep时这种情况也不会发生。

© www.soinside.com 2019 - 2024. All rights reserved.