程序从shell接收到的参数

来源:互联网 发布:唯一约束 mysql 编辑:程序博客网 时间:2024/05/21 22:47

参考文献:http://blog.sina.com.cn/s/blog_5d90e82f01014k5j.html

中心思想:shell 将通配符解析之后,作为参数传递为程序。

例:当前目录下有两个文件 file1 file2,在 shell 内执行 ls *时,程序运行过程如下:

1. shell 先解析 ls *中的通配符(×),得到 file1, file2

2. 将 file1,file2作为参数传递给 ls程序,而不是将*传递给ls 程序。

测试程序:

// t.c#include<stdio.h>#include<stdlib.h>int main(int argc,char **argv){    int i;    for(i=1;i<argc;++i) printf("%s ",argv[i]);    printf("\n");    return 0;    }

运行结果

$gcc t.c -o t$lsREADME  t  t.c  x$./t *README t t.c x$


 

 

原创粉丝点击