skip to content
Alvin Lucillo

Make and shell variables

/ 1 min read

In the example below, there are two variables with the same identifier: one is a Make variable with the value Bob and the other is a shell variable with the value Alice. A shell variable here is declared within the target show’s recipe, that’s why when it is expanded in the echo command with $$, the value is printed. To expand a Make variable, use $().

NAME = Bob

.PHONY: show

show:
	@NAME=Alice; echo "Hello, $$NAME"; echo "Hi, $(NAME)"
$ make show
Hello, Alice
Hi, Bob