Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does $$i do in this makefile loop?

Tags:

makefile

I have a simple loop in my makefile:

@ for i in $(APPDIRS) ; do \
    $(MAKE) -C $$i real_clean ; \
    done

I know $$ means process id of the script itself. What does the 'i' do? Am I iterating through the process id with the for loop?

like image 619
Christopher LaChance Avatar asked Oct 15 '25 15:10

Christopher LaChance


1 Answers

$ is used both as the variable identifier for make and for the shell. So if you want the shell to expand a variable, rather than having the makefile do it, you need to escape the $ by using $$.

As a quick example, let's assume APPDIRS=a b c d e f and MAKE=make (and i unset in the makefile). Then your shell sees:

for i in a b c d e f ; do
    make -C $i real_clean;
done

With a $ in place of the $$, it would see:

for i in a b c d e f ; do
    make -C  real_lean;
done

Which is definitely not what you want.

like image 152
Carl Norum Avatar answered Oct 18 '25 09:10

Carl Norum