Summary: Shell builtins not working unless explicitly set
SHELL to "sh"
Submitted by: None
Submitted on: Sat 18 Jan 2020 12:48:39 PM UTC
Severity: 3 - Normal
Item Group: Bug
Assigned to: None
Discussion Lock: Any
Component Version: 4.2.1
Operating System: POSIX-Based
Fixed Release: None
Triage Status: None
First, make tries to avoid invoking a shell as a performance improvement. If
make determines that the command to be invoked is a simple command it uses a
"fast path" where it simply forks and execs the command directly and doesn't
use a shell to do it.
GNU make contains a list of special commands which are known to be shell
built-ins, etc.; if the command starts with those make knows it needs to
invoke a shell _even if_ the command appears to be simple enough to invoke
Unfortunately, "type" is missing from that list; I have fixed that, along with
adding a few other missing items, and the fix will be in the next release.
As for setting SHELL; the documentation actually doesn't say the default value
of SHELL is "sh", it says the default value is "/bin/sh". If you used "SHELL
= /bin/sh" instead of "SHELL = sh" then you wouldn't see the odd behavior (it
would work the same as if you hadn't set SHELL). The change you observe is
because make also tries to detect whether the SHELL you set is a POSIX shell
or not. If make isn't sure, it will never choose the fast path and always
invoke the shell. Make is very conservative about this and only checks a few
well-known paths to decide whether the shell is POSIX or not; "sh" doesn't
meet that criteria so by setting "SHELL = sh" you've disabled fast-path for
all your recipes.
As a workaround for your current environment you can easily convince make to
always invoke a shell for your command simply by using a special character.
One simple one is ";"; if make sees a semicolon in the command it will always
skip the fast path and invoke a shell: