Re: using $(shell some sh command) when .SHELL has been (temporarily) set to non

Dmitry Goncharov <[email protected]> Sat, 12 Apr 2025 22:20:18 -0400
Newsgroups gmane.comp.gnu.make.general
Message-ID <CAG+Z0CsxtHp0ANSXZ07nQZT73vpo4R-zFTmvJ9vFHu-jm9rpmA@mail.gmail.com>
On Thu, Apr 3, 2025 at 3:35 PM Cook, Malcolm <[email protected]> wrote:
> I was surprised when setting SHELL (e.g. to `duckdb`) to find that a simply expanded variable that expands to $(shell some sh command) wound up passing 'my sh command' to duckdb rather than /bin/sh since It was expanded as part of a recipe that sets SHELL as a target specific variable for that recipe.


$(shell ...) passes the value of $(.SHELLFLAGS), followed by the
recipe to the value of $(SHELL).
In certain situations, make passes the value of $(SHELL) followed by
the value of $(.SHELLFLAGS), followed by the recipe to /bin/sh -c.
E.g. if $(.SHELLFLAGS) contains characters special to shell (such as $
[ ] = ' " ;), then make uses /bin/sh -c.

regards, Dmitry


>
> Should this behavior be considered "by design"?
>
> My workaround was to instead use $(call sh,some sh command), where sh is defined as:
>
> sh=$(let SHELL .SHELLFLAGS,/bin/sh -eu -o pipefail -c,$(shell $1))
>
> Is there perhaps a better workaround?
>
>