The examples there cannot be readily extended to support '(' ')' '-a'
'-o' '!' as in GNU find. In fact, I doubt that getopt can support
them.
If you think otherwise, could you show an example how '(' ')' '-a'
'-o' '!' can be supported with getopt?
If you need inspiration on how to write an option parser that matches
find(1), then read the source code for find [1] for inspiration. Note
that it does not use getopt() for parsing the bulk of its command line,
but its own hand-rolled parser. And therefore, any reimplementation
will likewise have to use custom manual parsing rather than being able
to rely on getopt-like libraries.
But your goal of re-writing find(1) in shell seems rather quixotic.
You're investing a lot of time into something that will never compete in
speed with the native C version, so about the only benefit you will get
from your efforts is a better appreciation of how shell programming
works (or does not work), and not something that anyone else would ever
want to use.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org