Could anyone please explain why following:

export PATH:=$(PATH):~/bin2
B:=$(shell PATH=$(PATH) testXq.sh)
$(warning $(B))

Is working properly showing results of run of the ~/bin2/testXq.sh, while following:

export PATH:=$(PATH):~/bin2
B:=$(shell testXq.sh)
$(warning $(B))

Returns an error:

make: testXq.sh: Command not found

I am on gmake v4.0


I realized that this is duplicate to https://stackoverflow.com/questions/2838715/makefile-variable-initialization-and-export

Which seems a bug in make https://savannah.gnu.org/bugs/?10593 .

  • It does not look like a bug in gmake. Note that this is completely non-portable stuff that regires gmake. – schily May 10 '16 at 9:41
  • It is: 1. Bug report exist. 2. Behaviour is not documented. 3. This question about gmake, and that is clear from the title. Why you talking about portability? – gena2x May 10 '16 at 12:48

It is most unlikely that gmake expands the tilde character, so the tilde remains in the PATH.

The shell however later expands the tilde when the PATH string is passed to the shell again.

Besides the fact that gmake does not expand the tilde character, there is another problem:

  • gmake seems to implement the export keyword only for "normal" shell commands that are run from rules (shell commands after a TAB inserted text).

This is not the first time when gmake causes problems with it's non-orthogonal implementation. Gmake e.g. claims to run on OpenVMS but the $(shell cmd) method does not work on OpenVMS.

  • No that's entirely not the case, entire PATH seems not propagated. – gena2x May 10 '16 at 9:03
  • But with a tilde inside and that tilde gets expanded to $HOME later in the shell in case you add PATH=$(PATH). – schily May 10 '16 at 11:23
  • Yes, so there is totally no problem with expansion. – gena2x May 10 '16 at 12:10
  • So you now understand my answer that explains why you need to pass the PATH= assignment to the shell? – schily May 10 '16 at 12:17
  • And you seem missed, totally, that is the problem here. Observed behavior is because any variable is not propagated to shell's environment automatically. If you do $(shell var=$(var) command) you just execute string in shell 'var=value_of_gmake_var command' which is interpreted by shell as 'set var to value_of_gmake and execute command', so that effectively propagation of single variable. Hope now it is clear? – gena2x May 10 '16 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.