'why do I get 'make: echo: Command not found' when I run 'make'?

Here is my Makefile code:

PATH = $(shell pwd)

run: 
    echo $(PATH)

I run make command and I get

echo /home/jht/test/makefile
make: echo: Command not found
make: *** [current_path.mk:5: run] Error 127

I am sure that I use Tab key not Space, and I run echo /home/jht/test/makefile, then I get /home/jht/test/makefile successfully.If I use echo "$(PATH)", I can get the expected result.

So, why do I get this error?



Solution 1:[1]

With...

PATH = $(shell pwd)

you explicitly set the PATH variable to the current working directory. That is then passed to the shell when you try to run...

echo $(PATH)

Hence, the shell can no longer locate echo (or anything else for that matter). Choose a variable name that's less likely to conflict with the current environment...

CURRENT_DIRECTORY = $(shell pwd)

run: 
    echo $(CURRENT_DIRECTORY)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 G.M.