-1

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

2
  • related - unix.stackexchange.com/questions/11530/… Commented May 9, 2016 at 17:41
  • No, I don't want to export anything to parent environment. It's not related at all. Commented May 9, 2016 at 17:43

2 Answers 2

1

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 .

2
  • It does not look like a bug in gmake. Note that this is completely non-portable stuff that regires gmake. Commented May 10, 2016 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? Commented May 10, 2016 at 12:48
-1

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.

9
  • No that's entirely not the case, entire PATH seems not propagated. Commented May 10, 2016 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). Commented May 10, 2016 at 11:23
  • Yes, so there is totally no problem with expansion. Commented May 10, 2016 at 12:10
  • So you now understand my answer that explains why you need to pass the PATH= assignment to the shell? Commented May 10, 2016 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? Commented May 10, 2016 at 12:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.