Makefile和$$的使用 [英] Makefile and use of $$
问题描述
所以我有一个Makefile,其中包含我想了解的以下代码:
So I have a Makefile in which I have the follwoing code that I try to understand:
for file_exe in `find . -name "zip_exe-*"`; do \
./$${file_exe} -d $(UNZIP_PATH)/lib; \
done
据我了解,这段代码将尝试找到一些可执行的zip并将这些zip文件提取到某个位置.但是令我困惑的是$${file_exe}
的工作方式.为什么需要双精度$$
?我猜这与某些bash命令是从makefile运行的事实有关,但是我无法向我自己解释为什么需要$$
,而简单的$
却不起作用,因为该命令正在运行子壳.
As I understand this piece of code will try to find some executable zip and the extract those zip files to a locations. But what puzzles me is how $${file_exe}
is working. Why is the double $$
needed? I guess it has something to do with the fact that some bash commands are running from a makefile, but I can't explain to myself why the $$
is needed and a simple $
does not work since this command is running a sub-shell anyway.
推荐答案
Make需要区分您是否希望$
用作引入可变变量引用,例如${FOOBAR}
或传递的普通$到外壳. 制作规范(部分宏)说,要执行后者,您可以必须使用$$
并将其替换为单个$
并传递给外壳.实际上,您的代码段读为
Make needs to distinguish whether you want a $
to use as introducing a make-variable reference, such as ${FOOBAR}
or as a plain $ passed on to the shell. The make specification (Section Macros) says that to do the latter, you must use $$
which is replaced by a single $
and passed to the shell. In effect, your snippet reads as
for file_exe in `find . -name "zip_exe-*"`; do \
./${file_exe} -d some/unzip/path/lib; \
done
到外壳.
样式注释:遍历反引号创建的文件列表被认为是不良样式,因为它可能会超出ARG_MAX限制.最好用
Style note: Iterating over file lists created by backticks is considered bad style, since it may overflow the ARG_MAX limit. Better to read the file names one-by-one with
find . -name "zip_exe-*" | \
while read -r file_exe; do \
./${file_exe} -d some/unzip/path/lib; \
done
这篇关于Makefile和$$的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!