从GNU Makefile调用`command -v find` [英] Calling `command -v find` from GNU Makefile
问题描述
我使用一个shell(bash,但我需要可移植性)和一个GNU Makefile.我有以下代码:
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
如预期的那样,传递了第一个命令,第二个命令以错误中止了Makefile.现在,我删除了>/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
产生以下错误?
make: command: Command not found.
推荐答案
从快速查看GNU make的源代码中的job.c
来看,它试图避免在可能的情况下(即当命令行足够简单时)启动shell. (格式为cmd args
,不带重定向,复合命令等),而shell是默认外壳.那么问题是command
是内置的,并且没有关联的可执行文件,因此来自make的错误消息.当您使用> /dev/null
时,它不会发生,因为make认为该命令过于复杂,并将其留给sh
来启动它.
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.
这篇关于从GNU Makefile调用`command -v find`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!