[comp.unix.wizards] globbing in the shell - let the shell handle it

mjr@osiris.UUCP (Marcus J. Ranum) (12/06/87)

> Rather than
> > int main(int argc, char *argv[], char *command_line);

	Since the program is already passed a pointer to the environment at
invocation, why not just have whatever shell you're running constantly keep
an environment variable pointing to CMDLINE or something like that ? 
That way, since you're already talking about re-writing loads of stuff, you
can re-write a shell to maintain the command line, and then re-write rm(1) or
whatever the way you want it. Better yet, your version of rm(1) can check to
see if CMDLINE is set in the invocation environment, and assume that if it is
your user DOES want all the extra safety, otherwise rm can just unlink the
damn file so the rest of us can get on with our work.

so:
	if(( cp = getenv("CMDLINE")) != NULL) {
		/* make it look like the MSDOS delete command */
		/* are you SURE (Y/N) ?  etc. */
	} else {
		/* make it look like rm(1) */
	}

	The big advantage to this suggestion is that people who want to have
all this kind of crap in their PATH can, and (hopefully) those users who manage
to "put up" with UNIX as-is can ignore it.

--mjr();
-- 
Once, there was NO fun... 
This was before MENU planning, FASHION statements or NAUTILUS equipment...
Then, in 1985..  FUN was completely encoded in this tiny MICROCHIP...  
It contains 14,768 vaguely amusing SIT-COM pilots!!

neilb@spinifex.unsw.oz (Neil Brown) (12/08/87)

I see a small problem with passing a program is pre-parsed command line
in an environment variable.

Consider:

% whiz-bang -lot -of -strnge *.x arguments

 in whiz-bang
	if (fork()==0)
		execl("/bin/rm","rm","-r",tempdir,0L),exit(1);
				/* remove my temporary directory */

	    inside rm
		look at argv
		look at CMDLINE
			They're SO different, what sort
			of shell is THIS charlie using.
			 But are they REALLY different, or is it
			some obscure substitution, I'll just check
			 "this wont take long guys" > /dev/tty
			 .......


You see, the environment gets inherited beyond the first process.
Of course you could do something like
	sprintf(envline,"CMDLINE%d=%s",getpid(),cmdline);
	( after fork, before exec)

	and getenv(strcat("CMDLINE",itoa(getpid()))) /* sort of */

but it gets uglier by the minute.

A thought I just had..
Maybe if rm started asking questions if any of the named files didn't exist.
This would catch  * .o type error as .o probably wouldn't exist.... just a
thought

NeilBrown