begin quoting Tracy R Reed as of Sat, Feb 04, 2006 at 08:20:34AM -0500: > Carl Lowenstein wrote: > > >It's not a property of "rmdir", it is a property of the shell. You > >realize, of course, that you were asking perhaps the most Frequently > >Asked of all Frequently Asked Questions. > > Years ago I too once asked this question. Don't recall where I found the > answer but it is a tricky one almost everyone asks at some point. How is > the special handling of -- a property of the shell?
For some reason I thought modern shells had optimized common commands, like rm, rmdir, mv, cp, etc., by making 'em builtins. However, looking at the list of builtins (in tcsh, use the command "builtins"; in bash, use "enable -p"), I don't see 'em. I could have sworn I once used a system where "which rm" told me it was a builtin, but none of the systems I've tried that on tonight exhibit that behavior. > I thought the -- > and -p and everything were just put into ARGV and rm itself parsed the > --. I just looked at getopt(3) and this seems to be the case. Any tool > that links in libgetopt for command line option parsing will get this > behavior. The "--" 'trick' is a convention that you get for free using libgetopt (and possibly other argument-parsing libraries -- I haven't looked); the shell just tokenizes the command-line, performs some substitution, and invokes the appropriate commands. Since what's passed to the program's main() method is just an array of strings (or an array of pointers to character arrays), there's really nothing the shell can do to indicate "here is where options stop". -- _ |\_ \| -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list
