grep is always recursive

Smoot Carl-Mitchell smoot at tic.com
Wed Jan 28 04:14:31 UTC 2009


On Tue, 2009-01-27 at 23:19 -0400, Derek Broughton wrote:

> You _could_ easily enough - you just say that the first non-option argument 
> terminates reading of options (just like -- does).  I should think you could 
> even drop a modified getopt onto your system that does that.

Will not work in all cases.  Suppose you have a directory with a file
called '-i'.  Then running ls with

ls *

will be the same as running

ls -i

The modified getopt will see the -i as an option and not as a file.  See
the man page for getopt for some interesting comments about this issue.
e.g.

man 3 getopt

and here:

http://refspecs.freestandards.org/LSB_1.2.0/gLSB/libutil-getopt-3.html

> Of course, there'd be howls from the geeks who've been using this for 
> decades.  In fact, I'm mostly aware that not every program uses getopt only 
> because some $%^&*( programs insist I put the options before any other 
> arguments!  I learned Unix when there was only one Unix, and I damn well put 
> my options where I feel like it!

And you could do anything you wanted with options and start them with
any character.  There is nothing particularly special about '-' as the
option prefix.  See 'dd', 'tar' and 'ps' for wacky option processing.
getopt is part of the POSIX specification.  So if you want your command
to be POSIX compliant in the way options are processed, then you will
want to use it.
-- 
Smoot Carl-Mitchell
Computer Systems and
Network Consultant
smoot at tic.com
+1 480 922 7313
cell: +1 602 421 9005




More information about the ubuntu-users mailing list