只有一个参数时,$ @和$ 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 targetapple这里),而$1是一个变量名为1 —没什么特别的。 Bash没有看到这些变量引用;他们由make处理。

$ cat Makefile 
1 = one 

target: 
    @echo '@ = [email protected]' 
    @echo '1 = $1' 

$ make 
@ = target 
1 = one