只有一个参数时,$ @和$ 1之间有什么区别?
问题描述:
有一些C代码:
apple.c
#include<stdio.h>
int main(void)
{
printf("apple\n");
return 0;
}
的Makefile
apple:
gcc -c [email protected]
gcc [email protected] -o [email protected]
$ make apple
和它完美的作品。但是,如果我修改Makefile
为:
apple:
gcc -c $1.c
gcc $1.o -o $1
$ make apple
它不工作。只有一个参数时,[email protected]
和$1
之间有什么区别?
答
在shell脚本中,不会有任何区别。但是这是一个Makefile,所以这些参考文献是make variables。 [email protected]
是name of the rule target(apple
这里),而$1
是一个变量名为1
—没什么特别的。 Bash没有看到这些变量引用;他们由make处理。
$ cat Makefile
1 = one
target:
@echo '@ = [email protected]'
@echo '1 = $1'
$ make
@ = target
1 = one