Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling `command -v find` from 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

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.
like image 406
Johannes Avatar asked Nov 16 '25 10:11

Johannes


1 Answers

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.

like image 137
Virgile Avatar answered Nov 18 '25 19:11

Virgile



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!