bugmake - Bugs: bug #57625, Shell builtins not working unless...

 
 

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

Submitter:  None
Submitted:  Sat 18 Jan 2020 12:48:39 PM UTC
   
 
Severity:  3 - Normal Item Group:  Bug
Status:  Fixed Privacy:  Public
Assigned to:  psmith Open/Closed:  Closed
Component Version:  4.2.1 Operating System:  POSIX-Based
Fixed Release:  4.3 Triage Status:  Small Effort
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 18 Jan 2020 03:25:09 PM UTC, 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;


Paul D. Smith <psmith>
Group administrator
Sat 18 Jan 2020 12:48:39 PM UTC, original submission:  

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.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-01-18 psmith StatusNone Fixed
        Assigned toNone psmith
        Open/ClosedOpen Closed
        Fixed ReleaseNone 4.3
        Triage StatusNone Small Effort

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code