> -----Original Message----- > From: Cook, Malcolm <m...@stowers.org> > Sent: Wednesday, April 9, 2025 8:14 AM > To: Dmitry Goncharov <dgoncha...@users.sf.net> > Cc: help-make@gnu.org > Subject: RE: using $(shell some sh command) when .SHELL has been > (temporarily) set to non > > Sure, thanks for taking an interest.... > > The following output demonstrates the issue first with changing the shell to > `bash` and then changing it to duckdb. Note, the script that produces this > output has -n in the shebang line, so the recipes are not event being run. > > GNU Make 4.4.1 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2023 Free > Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later > <https://gnu.org/licenses/gpl.html> This is free software: you are free to > change and redistribute it. There is NO WARRANTY, to the extent permitted by > law. > printf 'a /bin/sh\n' > printf 'b /bin/bash\n' > printf 'c /bin/sh\n' > select 'd /bin/sh' > Parser Error: syntax error at or near "echo" > LINE 1: echo $0 > ^ > select 'e ' > > > here is the script: > > #!/bin/env -S make -n -f > $(info $(shell ${MAKE} --version)) > sh=$(let SHELL .SHELLFLAGS,/bin/sh -eu -o pipefail -c,$(shell $1)) > > echoa=$(shell echo $$0) > echob=$(shell echo $$0) > echoc=$(call sh,echo $$0) > echod=$(call sh,echo $$0) > echoe=$(shell echo $$0) > > all=a b c d e > .PHONY: all ${all} > > all:: ${all} > > a: > @printf '$@ $(echoa)\n' > > b: SHELL=/bin/bash > b: > @printf '$@ $(echob)\n' > > c: SHELL=/bin/bash > c: > @printf '$@ $(echoc)\n' > > d: SHELL=duckdb > d: .SHELLOPT=-c > d: > select '$@ $(echod)\n' > > e: SHELL=duckdb > e: > select '$@ $(echoe)'
This version is perhaps more succinct in demonstrating the issue. It produces same results: #!/bin/env -S make -k -n -f $(info $(shell ${MAKE} --version)) sh=$(let SHELL .SHELLFLAGS,/bin/sh -eu -o pipefail -c,$(shell $1)) echoa=$(shell echo $$0) echob=$(shell echo $$0) echoc=$(call sh,echo $$0) echod=$(call sh,echo $$0) echoe=$(shell echo $$0) all=a b c d e .PHONY: all ${all} all:: ${all} b: SHELL=/bin/bash a b c: @printf '$@ $(echo${@})\n' d e: SHELL=duckdb d e: select '$@ $(echo${@})\n' > > > > -----Original Message----- > > From: Dmitry Goncharov <dgoncha...@users.sf.net> > > Sent: Wednesday, April 9, 2025 6:45 AM > > To: Cook, Malcolm <m...@stowers.org> > > Cc: help-make@gnu.org > > Subject: Re: using $(shell some sh command) when .SHELL has been > > (temporarily) set to non > > > > On Thu, Apr 3, 2025 at 3:35 PM Cook, Malcolm <m...@stowers.org> wrote: > > > > > > I expect GNU make is working as expected, but I could use confirmation > > > .... > > > > > > 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. > > > > > > 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? > > > > > > > Can you post the makefile code? > > > > regards, Dmitry