UNIX command line arguments

Dan KoGai dankg at tornado.Berkeley.EDU
Sat Jun 9 02:29:03 AEST 1990


In article <352 at ankh.ftl.fl.us> chin at ankh.ftl.fl.us (Albert Chin) writes:

>Under UNIX, you can specify multiple filenames with similar characteristics
>with the "*" argument and also the "[..]". For instance, to remove all
>files of the type "file.1, file.2, file.3" you would type "rm file.*".
>Also, you could "mv file.* myfile.*". I woule like to know how the argv
>arguments get interpreted when this happens. I can understand that under
>"rm file.*" all files matching that parameter would be translated on the
>command line as if "rm file.1 file.2 ..." had been typed. But what about
>the case of "mv file.* myfile.*". Would **argv then contain "mv file.1
>myfile.1 file.2 myfile.2 file.3 myfile.3". If so, then I understand, but
>if now, then how else does it work.

	Simple:  It's shell's job to expand * and other character (called
globbing).  On csh you can turn off this feature by "set noglob" and
characters such as '*' are treated leterally (this is necessary when using
tset, et al).
	So your argv will receive literal names of filenames, not a single
'*'.  And this also apply for directories and variable substitution:
if the shell (here I use csh) recieves "~/foo" and your $HOME is
/usr/account/chin, your argv will receive /usr/account/chin/foo.
	I'm not sure if it applies to other CLI OS but I think so.
(DOS, OS/2, OS-9, you name it).  The following code is a simple program
to print what exactly your argv got.

/* start code */

main(argc, argv)
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])
	}
}

/* end code */

----------------
____  __  __    + Dan The "Pnews -h~/.rnhead < .article" Man
    ||__||__|   + E-mail:	dankg at ocf.berkeley.edu
____| ______ 	+ Voice:	+1 415-549-6111
|     |__|__|	+ USnail:	1730 Laloma Berkeley, CA 94709 U.S.A
|___  |__|__|	+	
    |____|____	+ "What's the biggest U.S. export to Japan?" 	
  \_|    |      + "Bullshit.  It makes the best fertilizer for their rice"



More information about the Comp.lang.c mailing list