Today, I suddenly think of a question: what happens when the input parameter of the command line program is a wildcard (such as./A. out? Is the input parameter * obtained by the program?
Source code:
#include <stdio.h>int main(int argc, char *argv[]){ int i; printf("argc: %d\n", argc); for(i = 0; i < argc; i++) printf("argv[%d]: %s\n", i, argv[i]); return 0;}
Execution result:
$ ls111.txt 2byte.txt a.out main.c minicom.txt src
$ ./a.out *argc: 7argv[0]: ./a.outargv[1]: 111.txtargv[2]: 2byte.txtargv[3]: a.outargv[4]: main.cargv[5]: minicom.txtargv[6]: src
$ ./a.out *.txtargc: 4argv[0]: ./a.outargv[1]: 111.txtargv[2]: 2byte.txtargv[3]: minicom.txt
Running environment:
$uname -aLinux xxxxx 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:24 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
$ gcc --versiongcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2Copyright (C) 2010 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Conclusion: when the input parameter given when the program is running is a wildcard, the input parameter actually obtained by the program is not a simple wildcard, but an actual expansion of the wildcard.
PS. It seems a little strange.