Wildcard input parameters of the command line program

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.