Search code examples
windowsconsoleenvironment-variablesechonmake

How do I get and print value of an environment variable?


I want to print value from a Windows environment variable, say, path or errorlevel, I've tried this but it doesn't work. Output this in my console:

(without consider spaces/tabs which it outputs):

echo %PATH
%PATH

Makefile:

PATH=$(PATH);\nonesuch

all:
    echo %PATH%

command-line:

nmake /E

How do I fix it?

NOTE: Visual Studio's binary path is in my PATH variable, that's why I'm calling this outside VS console


Solution

  • The percent sign % has special meaning in Makefiles.

    In order to perform the Windows batch-file substitution, you need to escape it like this:

    echo %%PATH%%
    

    This seems to work too:

    "echo %PATH%"
    

    Another option is to perform the substitution on the Make side, but that's a different thing:

    echo $(PATH)