Calling `command -v find` from GNU Makefile

孤者浪人 提交于 2019-12-08 03:08:07

问题


I use a shell (bash, but I need portability) and a GNU Makefile. I have this code:

check_commands:
        command -v find >/dev/null
        command -v asdf >/dev/null

As supposed, the first command is passed, the second aborts the Makefile with an error. Now, I remove the >/dev/null. Why does then

check_commands:
        command -v find

produce the following error?

make: command: Command not found.

回答1:


Judging from a quick look at job.c in GNU make's sources, it attempts to avoid launching a shell when it can, i.e. when the command line is simple enough (of the form cmd args, without redirection, compound commands, etc.) and the shell is the default one. The issue is then that command is a built-in and does not have an associated executable, hence the error message from make. It does not occur when you have > /dev/null as make considers the command as too complicated and leaves it to sh to launch it.



来源:https://stackoverflow.com/questions/12989869/calling-command-v-find-from-gnu-makefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!