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

The Mask picture The Mask · May 28, 2014 · Viewed 20.3k times · Source

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

Answer

Yirkha picture Yirkha · May 28, 2014

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)