makefileenvironment-variables

Why is Makefile export adding an extra `=` to my variables?


I have this Makefile:

export $(shell echo "truman=name")

env:
    export

When I run make env, I see:

export truman="name="

Why is there an extra = in my export?


Solution

  • This looks like a Make bug, and I think I know what's going on.

    make sees export $(...), and thinks the entire $(...) is the variable name, without checking it for =. Since it thinks no value is specified, it adds = at the end.

    Then the whole string truman=name= gets passed to something like putenv, which considers the first = to be the separator, and treats name= as the value.

    As said in the other answers, the fix is to use $(eval ).