我的 makefile 中有一个简单的循环:
@ for i in $(APPDIRS) ; do \
$(MAKE) -C $$i real_clean ; \
done
Run Code Online (Sandbox Code Playgroud)
我知道 $$ 表示脚本本身的进程 ID 。“我”有什么作用?我是否使用 for 循环迭代进程 id?
$既用作 shell 的变量标识符,make又用作 shell 的变量标识符。因此,如果您希望shell扩展变量,而不是让 makefile 执行此操作,则需要$使用 来转义$$。
作为一个简单的例子,我们假设APPDIRS=a b c d e fand MAKE=make(并i在 makefile 中取消设置)。然后你的 shell 会看到:
for i in a b c d e f ; do
make -C $i real_clean;
done
Run Code Online (Sandbox Code Playgroud)
用 a$代替$$,它将看到:
for i in a b c d e f ; do
make -C real_lean;
done
Run Code Online (Sandbox Code Playgroud)
这绝对不是你想要的。