[bug #57625] Shell builtins not working unless explicitly set SHELL to "sh"

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #57625] Shell builtins not working unless explicitly set SHELL to "sh"

Bogdan Barbu
URL:
  <https://savannah.gnu.org/bugs/?57625>

                 Summary: Shell builtins not working unless explicitly set
SHELL to "sh"
                 Project: make
            Submitted by: None
            Submitted on: Sat 18 Jan 2020 12:48:39 PM UTC
                Severity: 3 - Normal
              Item Group: Bug
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
       Component Version: 4.2.1
        Operating System: POSIX-Based
           Fixed Release: None
           Triage Status: None

    _______________________________________________________

Details:

Example contents of makefile:


.POSIX:
#SHELL = sh
.PHONY: run
run:
        type make


The target fails because "make: type: Command not found".
If you uncomment the line, it works just fine and outputs "/usr/bin/make". The
documentation
(https://www.gnu.org/software/make/manual/html_node/Choosing-the-Shell.html#Choosing-the-Shell)
says that the default shell is "sh", so I'm not sure why setting SHELL to "sh"
should affect the execution of commands.




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57625>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #57625] Shell builtins not working unless explicitly set SHELL to "sh"

Bogdan Barbu
Update of bug #57625 (project make):

                  Status:                    None => Fixed                  
             Assigned to:                    None => psmith                
             Open/Closed:                    Open => Closed                
           Fixed Release:                    None => SCM                    
           Triage Status:                    None => Small Effort          

    _______________________________________________________

Follow-up Comment #1:

There are a confluence of factors involved here.

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
directly.

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:


.POSIX:
run:
        type make;


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57625>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/