[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

shell function: confusing error when shebang incorrect

From: Kirill Elagin
Subject: shell function: confusing error when shebang incorrect
Date: Sun, 9 Oct 2022 11:15:51 -0400


There is a bit of unexpected behaviour in the `shell` function (due to
the undocumented fact that it sometimes avoids actually calling the

$ cat Makefile
FOO:=$(shell ./foo.sh)

$ cat foo.sh
echo hi

$ make
make: ./foo.sh: No such file or directory
make: *** No targets.  Stop.

$ ./foo.sh
zsh: ./foo.sh: bad interpreter: /bin/ohno: no such file or directory

The “no such file or directory” error from Make is very confusing and
unexpected in this situation, especially given that it is not the
error that the shell would return.

The reason for it is that, while undocumented, the `shell` function
will try to avoid calling the shell in simple cases like this one and
will directly exec the command. However, the error returned by
`execve` is ambiguous:

> ENOENT  The file pathname or a script or ELF interpreter does not exist.

Shells (bash, zsh) disambiguate it themselves, i.e. there is extra
logic for the case of ENOENT, while Make simply fails with what it
sees, resulting in a puzzling error message.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]