UNIX command line arguments

Conor P. Cahill cpcahil at virtech.uucp
Fri Jun 8 12:34:49 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

First off, you can't do "mv file.* myfile.*" if you think this will move
all of the "file.*" files to "myfile.*" files.  mv only as two modes of
operation: mv file.orig file.new or mv filelist directory.

The expansion of the shell filename wilcards is performed by the shell
itself as the command line is processed by the shell before the indicated
program is executed.  This processing used to be performed by a "glob" 
function (hence the message "glob [confirm]" from the PWB and version 6
rm command when a wildcard was specified).

>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.

The interpretation is always in place in sorted order.  So if your 
directory contained the files:

	file.1
	file.2
	file.3
	file.4
	myfile.8
	myfile.9
	myfile.10

and you executed "echo file.* myfile.*"
the argv array for echo would look like:

	argv[1] = "file.1"
	argv[2] = "file.1"
	argv[3] = "file.1"
	argv[4] = "file.1"
	argv[5] = "myfile.10"
	argv[6] = "myfile.8"
	argv[7] = "myfile.9"

Note that I start with subscript 1, since argv[0] would be "echo".


-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.lang.c mailing list