This is the Makefile content:
sgr0 := $(shell tput sgr0)
bold := $(shell tput bold)
orange := $(shell tput setaf 166)
test:
@echo "$(bold)$(orange)ENV_VARIABLE:(sgr0) ${ENV_VARIABLE}"
You run the following command in bash:
export ENV_VARIABLE=value
Then you call call make test and get the following output:
ENV_VARIABLE: value
Instead, if you modify the Makefile test target like this:
test:
@echo "$(bold)$(orange)ENV_VARIABLE:(sgr0) $${ENV_VARIABLE}"
The result of calling make test would be:
ENV_VARIABLE: $ENV_VARIABLE
So I'm pretty confused, because the GNU make official doc says to use $$ for shell variables:
Variable and function references in recipes have identical syntax and semantics to references elsewhere in the makefile. They also have the same quoting rules: if you want a dollar sign to appear in your recipe, you must double it (‘$$’). For shells like the default shell, that use dollar signs to introduce variables, it’s important to keep clear in your mind whether the variable you want to reference is a make variable (use a single dollar sign) or a shell variable (use two dollar signs).
But if I use $$, then I don't see how my variable gets expanded. So, in order to follow the best practice of using $$ for shell variables and $ for make variables, I need to give up on being able to read how the shell variable gets expanded?
UPDATE:
You execute export ENV=test.txt
Makefile content:
test:
touch $(ENV)
this works as it returns touch test.txt
Instead, if you change to $$(ENV), it will throw an error.