Path: utzoo!attcan!uunet!samsung!sdd.hp.com!ucsd!ucbvax!agate!tornado.Berkeley.EDU!dankg From: dankg@tornado.Berkeley.EDU (Dan KoGai) Newsgroups: comp.lang.c Subject: Re: UNIX command line arguments Message-ID: <1990Jun8.162903.7297@agate.berkeley.edu> Date: 8 Jun 90 16:29:03 GMT References: <352@ankh.ftl.fl.us> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: dankg@tornado.Berkeley.EDU (Dan KoGai) Organization: ucb Lines: 48 In article <352@ankh.ftl.fl.us> chin@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@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"